2021-10-29 11:44:01 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2021-10-29 11:44:01 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2021-10-29 11:44:01 +03:00
|
|
|
* @since v1.4.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2021-11-06 13:15:32 +03:00
|
|
|
require_once __DIR__ . '/../core/EA_Migration.php';
|
2021-10-29 11:44:01 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instance library.
|
|
|
|
*
|
|
|
|
* Handles all Easy!Appointments instance related functionality.
|
|
|
|
*
|
|
|
|
* @package Libraries
|
|
|
|
*/
|
|
|
|
class Instance {
|
|
|
|
/**
|
|
|
|
* @var EA_Controller
|
|
|
|
*/
|
|
|
|
protected $CI;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installation constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->CI =& get_instance();
|
|
|
|
|
|
|
|
$this->CI->load->model('admins_model');
|
|
|
|
$this->CI->load->model('services_model');
|
|
|
|
$this->CI->load->model('providers_model');
|
|
|
|
$this->CI->load->model('customers_model');
|
|
|
|
|
|
|
|
$this->CI->load->library('timezones');
|
2021-11-06 13:15:32 +03:00
|
|
|
$this->CI->load->library('migration');
|
2021-10-29 11:44:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Migrate the database to the latest state.
|
|
|
|
*
|
2021-11-06 17:17:03 +03:00
|
|
|
* @param string $type Provide "fresh" to revert previous migrations and start from the beginning or "up"/"down" to step.
|
2021-10-29 11:44:01 +03:00
|
|
|
*/
|
|
|
|
public function migrate(string $type = '')
|
|
|
|
{
|
2021-11-06 17:17:03 +03:00
|
|
|
$current_version = $this->CI->migration->current_version();
|
|
|
|
|
|
|
|
if ($type === 'up')
|
|
|
|
{
|
|
|
|
if ( ! $this->CI->migration->version($current_version + 1))
|
|
|
|
{
|
|
|
|
show_error($this->CI->migration->error_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($type === 'down')
|
|
|
|
{
|
|
|
|
if ( ! $this->CI->migration->version($current_version - 1))
|
|
|
|
{
|
|
|
|
show_error($this->CI->migration->error_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-29 11:44:01 +03:00
|
|
|
if ($type === 'fresh' && ! $this->CI->migration->version(0))
|
|
|
|
{
|
|
|
|
show_error($this->CI->migration->error_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->CI->migration->latest() === FALSE)
|
|
|
|
{
|
|
|
|
show_error($this->CI->migration->error_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Seed the database with test data.
|
|
|
|
*/
|
|
|
|
public function seed()
|
|
|
|
{
|
|
|
|
// Settings
|
|
|
|
setting([
|
|
|
|
'company_name' => 'Company Name',
|
|
|
|
'company_email' => 'info@example.org',
|
|
|
|
'company_link' => 'https://example.org',
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Admin
|
|
|
|
$this->CI->admins_model->save([
|
|
|
|
'first_name' => 'John',
|
|
|
|
'last_name' => 'Doe',
|
|
|
|
'email' => 'john@example.org',
|
|
|
|
'phone_number' => '+10000000000',
|
|
|
|
'settings' => [
|
|
|
|
'username' => 'administrator',
|
|
|
|
'password' => 'administrator',
|
|
|
|
'notifications' => TRUE,
|
|
|
|
'calendar_view' => CALENDAR_VIEW_DEFAULT
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Service
|
|
|
|
$service_id = $this->CI->services_model->save([
|
|
|
|
'name' => 'Service',
|
|
|
|
'duration' => '30',
|
|
|
|
'price' => '0',
|
|
|
|
'currency' => '',
|
|
|
|
'availabilities_type' => 'flexible',
|
|
|
|
'attendants_number' => '1'
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Provider
|
|
|
|
$this->CI->providers_model->save([
|
|
|
|
'first_name' => 'Jane',
|
|
|
|
'last_name' => 'Doe',
|
|
|
|
'email' => 'jane@example.org',
|
|
|
|
'phone_number' => '+10000000000',
|
|
|
|
'services' => [
|
|
|
|
$service_id
|
|
|
|
],
|
|
|
|
'settings' => [
|
|
|
|
'username' => 'janedoe',
|
|
|
|
'password' => 'janedoe',
|
|
|
|
'working_plan' => setting('company_working_plan'),
|
|
|
|
'notifications' => TRUE,
|
|
|
|
'google_sync' => FALSE,
|
|
|
|
'sync_past_days' => 30,
|
|
|
|
'sync_future_days' => 90,
|
|
|
|
'calendar_view' => CALENDAR_VIEW_DEFAULT
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Customer
|
|
|
|
$this->CI->customers_model->save([
|
|
|
|
'first_name' => 'James',
|
|
|
|
'last_name' => 'Doe',
|
|
|
|
'email' => 'james@example.org',
|
|
|
|
'phone_number' => '+10000000000',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a database backup file.
|
|
|
|
*
|
|
|
|
* @param string|null $path Override the default backup path (storage/backups/*).
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public function backup(string $path = NULL)
|
|
|
|
{
|
|
|
|
$path = $path ?? APPPATH . '/../storage/backups';
|
|
|
|
|
|
|
|
if ( ! file_exists($path))
|
|
|
|
{
|
2022-06-20 12:31:11 +03:00
|
|
|
throw new InvalidArgumentException('The backup path does not exist: ' . $path);
|
2021-10-29 11:44:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! is_writable($path))
|
|
|
|
{
|
2022-06-20 12:31:11 +03:00
|
|
|
throw new RuntimeException('The backup path is not writable: ' . $path);
|
2021-10-29 11:44:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$contents = $this->CI->dbutil->backup();
|
|
|
|
|
|
|
|
$filename = 'easyappointments-backup-' . date('Y-m-d-His') . '.gz';
|
|
|
|
|
|
|
|
write_file(rtrim($path, '/') . '/' . $filename, $contents);
|
|
|
|
}
|
|
|
|
}
|