2021-10-29 11:44:01 +03:00
|
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2024-01-01 01:14:38 +03:00
|
|
|
|
* MaketRandevu - MAKET Randevu Portalı
|
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
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
class Instance
|
|
|
|
|
{
|
2021-10-29 11:44:01 +03:00
|
|
|
|
/**
|
2023-03-13 11:06:18 +03:00
|
|
|
|
* @var EA_Controller|CI_Controller
|
2021-10-29 11:44:01 +03:00
|
|
|
|
*/
|
2023-03-13 11:06:18 +03:00
|
|
|
|
protected EA_Controller|CI_Controller $CI;
|
2021-10-29 11:44:01 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Installation constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$this->CI = &get_instance();
|
2021-10-29 11:44:01 +03:00
|
|
|
|
|
|
|
|
|
$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
|
|
|
|
*/
|
2023-03-13 11:06:18 +03:00
|
|
|
|
public function migrate(string $type = ''): void
|
2021-10-29 11:44:01 +03:00
|
|
|
|
{
|
2021-11-06 17:17:03 +03:00
|
|
|
|
$current_version = $this->CI->migration->current_version();
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if ($type === 'up') {
|
|
|
|
|
if (!$this->CI->migration->version($current_version + 1)) {
|
2021-11-06 17:17:03 +03:00
|
|
|
|
show_error($this->CI->migration->error_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if ($type === 'down') {
|
|
|
|
|
if (!$this->CI->migration->version($current_version - 1)) {
|
2021-11-06 17:17:03 +03:00
|
|
|
|
show_error($this->CI->migration->error_string());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if ($type === 'fresh' && !$this->CI->migration->version(0)) {
|
2021-10-29 11:44:01 +03:00
|
|
|
|
show_error($this->CI->migration->error_string());
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if ($this->CI->migration->latest() === false) {
|
2021-10-29 11:44:01 +03:00
|
|
|
|
show_error($this->CI->migration->error_string());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Seed the database with test data.
|
2023-03-01 11:00:24 +03:00
|
|
|
|
*
|
|
|
|
|
* @return string Return's the administrator user password.
|
2023-11-29 12:24:09 +03:00
|
|
|
|
*
|
2023-03-17 09:20:29 +03:00
|
|
|
|
* @throws Exception
|
2021-10-29 11:44:01 +03:00
|
|
|
|
*/
|
2023-03-01 11:00:24 +03:00
|
|
|
|
public function seed(): string
|
2021-10-29 11:44:01 +03:00
|
|
|
|
{
|
|
|
|
|
// Settings
|
2023-11-29 12:24:09 +03:00
|
|
|
|
|
2021-10-29 11:44:01 +03:00
|
|
|
|
setting([
|
|
|
|
|
'company_name' => 'Company Name',
|
|
|
|
|
'company_email' => 'info@example.org',
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'company_link' => 'https://example.org',
|
2021-10-29 11:44:01 +03:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Admin
|
2023-03-01 11:00:24 +03:00
|
|
|
|
|
2023-11-29 12:43:08 +03:00
|
|
|
|
$password = 'administrator';
|
|
|
|
|
|
2021-10-29 11:44:01 +03:00
|
|
|
|
$this->CI->admins_model->save([
|
|
|
|
|
'first_name' => 'John',
|
|
|
|
|
'last_name' => 'Doe',
|
|
|
|
|
'email' => 'john@example.org',
|
|
|
|
|
'phone_number' => '+10000000000',
|
|
|
|
|
'settings' => [
|
|
|
|
|
'username' => 'administrator',
|
2023-11-29 12:43:08 +03:00
|
|
|
|
'password' => $password,
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'notifications' => true,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'calendar_view' => CALENDAR_VIEW_DEFAULT,
|
|
|
|
|
],
|
2021-10-29 11:44:01 +03:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Service
|
2023-03-01 11:00:24 +03:00
|
|
|
|
|
2021-10-29 11:44:01 +03:00
|
|
|
|
$service_id = $this->CI->services_model->save([
|
|
|
|
|
'name' => 'Service',
|
|
|
|
|
'duration' => '30',
|
|
|
|
|
'price' => '0',
|
|
|
|
|
'currency' => '',
|
|
|
|
|
'availabilities_type' => 'flexible',
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'attendants_number' => '1',
|
2021-10-29 11:44:01 +03:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Provider
|
2023-03-01 11:00:24 +03:00
|
|
|
|
|
2021-10-29 11:44:01 +03:00
|
|
|
|
$this->CI->providers_model->save([
|
|
|
|
|
'first_name' => 'Jane',
|
|
|
|
|
'last_name' => 'Doe',
|
|
|
|
|
'email' => 'jane@example.org',
|
|
|
|
|
'phone_number' => '+10000000000',
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'services' => [$service_id],
|
2021-10-29 11:44:01 +03:00
|
|
|
|
'settings' => [
|
|
|
|
|
'username' => 'janedoe',
|
2023-03-01 11:00:24 +03:00
|
|
|
|
'password' => random_string(),
|
2021-10-29 11:44:01 +03:00
|
|
|
|
'working_plan' => setting('company_working_plan'),
|
2023-07-29 13:02:52 +03:00
|
|
|
|
'working_plan_exceptions' => '{}',
|
2023-11-29 12:24:09 +03:00
|
|
|
|
'notifications' => true,
|
|
|
|
|
'google_sync' => false,
|
2021-10-29 11:44:01 +03:00
|
|
|
|
'sync_past_days' => 30,
|
|
|
|
|
'sync_future_days' => 90,
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'calendar_view' => CALENDAR_VIEW_DEFAULT,
|
|
|
|
|
],
|
2021-10-29 11:44:01 +03:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Customer
|
2023-03-01 11:00:24 +03:00
|
|
|
|
|
2021-10-29 11:44:01 +03:00
|
|
|
|
$this->CI->customers_model->save([
|
|
|
|
|
'first_name' => 'James',
|
|
|
|
|
'last_name' => 'Doe',
|
|
|
|
|
'email' => 'james@example.org',
|
2023-12-22 13:35:41 +03:00
|
|
|
|
'phone_number' => '+10000000000',
|
2021-10-29 11:44:01 +03:00
|
|
|
|
]);
|
2023-03-01 11:00:24 +03:00
|
|
|
|
|
|
|
|
|
return $password;
|
2021-10-29 11:44:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a database backup file.
|
|
|
|
|
*
|
|
|
|
|
* @param string|null $path Override the default backup path (storage/backups/*).
|
|
|
|
|
*
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
public function backup(string $path = null): void
|
2021-10-29 11:44:01 +03:00
|
|
|
|
{
|
|
|
|
|
$path = $path ?? APPPATH . '/../storage/backups';
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 12:24:09 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|