2020-09-23 12:24:20 +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
|
2020-09-23 12:24:20 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2020-11-14 22:36:25 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2020-09-23 12:24:20 +03:00
|
|
|
* @since v1.3.2
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2020-12-04 13:49:57 +03:00
|
|
|
require_once __DIR__ . '/Google.php';
|
2020-09-23 12:24:20 +03:00
|
|
|
|
|
|
|
/**
|
2021-11-06 18:21:27 +03:00
|
|
|
* Console controller.
|
2020-09-23 12:24:20 +03:00
|
|
|
*
|
2021-10-28 15:01:17 +03:00
|
|
|
* Handles all the Console related operations.
|
2020-09-23 12:24:20 +03:00
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
class Console extends EA_Controller
|
|
|
|
{
|
2020-09-23 12:24:20 +03:00
|
|
|
/**
|
|
|
|
* Console constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
if (!is_cli()) {
|
2020-09-23 12:24:20 +03:00
|
|
|
exit('No direct script access allowed');
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
2020-12-04 15:28:18 +03:00
|
|
|
$this->load->dbutil();
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2021-10-29 11:44:01 +03:00
|
|
|
$this->load->library('instance');
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2020-12-04 13:49:57 +03:00
|
|
|
$this->load->model('admins_model');
|
|
|
|
$this->load->model('customers_model');
|
2020-09-23 12:24:20 +03:00
|
|
|
$this->load->model('providers_model');
|
2020-12-04 13:49:57 +03:00
|
|
|
$this->load->model('services_model');
|
|
|
|
$this->load->model('settings_model');
|
2020-09-23 12:24:20 +03:00
|
|
|
}
|
|
|
|
|
2020-12-09 15:17:45 +03:00
|
|
|
/**
|
|
|
|
* Perform a console installation.
|
|
|
|
*
|
|
|
|
* Use this method to install Easy!Appointments directly from the terminal.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* php index.php console install
|
2024-04-26 17:36:14 +03:00
|
|
|
*
|
|
|
|
* @throws Exception
|
2020-12-09 15:17:45 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function install(): void
|
2020-12-09 15:17:45 +03:00
|
|
|
{
|
2021-10-29 11:44:01 +03:00
|
|
|
$this->instance->migrate('fresh');
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2023-03-01 11:00:24 +03:00
|
|
|
$password = $this->instance->seed();
|
2021-10-28 15:01:17 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
response(
|
2023-12-22 13:35:41 +03:00
|
|
|
PHP_EOL . '⇾ Installation completed, login with "administrator" / "' . $password . '".' . PHP_EOL . PHP_EOL,
|
2023-11-29 12:24:09 +03:00
|
|
|
);
|
2020-12-09 15:17:45 +03:00
|
|
|
}
|
|
|
|
|
2020-09-23 12:24:20 +03:00
|
|
|
/**
|
|
|
|
* Migrate the database to the latest state.
|
|
|
|
*
|
2021-10-29 11:44:01 +03:00
|
|
|
* Use this method to upgrade an Easy!Appointments instance to the latest database state.
|
2020-09-23 12:24:20 +03:00
|
|
|
*
|
|
|
|
* Notice:
|
|
|
|
*
|
|
|
|
* Do not use this method to install the app as it will not seed the database with the initial entries (admin,
|
2024-04-26 17:36:14 +03:00
|
|
|
* provider, service, settings etc.).
|
2020-09-23 12:24:20 +03:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* php index.php console migrate
|
2020-12-02 23:21:35 +03:00
|
|
|
*
|
2020-12-04 13:49:57 +03:00
|
|
|
* php index.php console migrate fresh
|
|
|
|
*
|
2020-12-02 23:21:35 +03:00
|
|
|
* @param string $type
|
2020-09-23 12:24:20 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function migrate(string $type = ''): void
|
2020-09-23 12:24:20 +03:00
|
|
|
{
|
2021-10-29 11:44:01 +03:00
|
|
|
$this->instance->migrate($type);
|
2020-09-23 12:24:20 +03:00
|
|
|
}
|
|
|
|
|
2020-12-04 13:49:57 +03:00
|
|
|
/**
|
|
|
|
* Seed the database with test data.
|
|
|
|
*
|
|
|
|
* Use this method to add test data to your database
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* php index.php console seed
|
2024-04-26 17:36:14 +03:00
|
|
|
* @throws Exception
|
2020-12-04 13:49:57 +03:00
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function seed(): void
|
2020-12-04 13:49:57 +03:00
|
|
|
{
|
2021-10-29 11:44:01 +03:00
|
|
|
$this->instance->seed();
|
2020-12-04 13:49:57 +03:00
|
|
|
}
|
|
|
|
|
2020-12-04 15:28:18 +03:00
|
|
|
/**
|
2021-10-29 11:44:01 +03:00
|
|
|
* Create a database backup file.
|
2020-12-04 15:28:18 +03:00
|
|
|
*
|
2021-10-28 15:01:17 +03:00
|
|
|
* Use this method to back up your Easy!Appointments data.
|
2020-12-04 15:28:18 +03:00
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* php index.php console backup
|
|
|
|
*
|
|
|
|
* php index.php console backup /path/to/backup/folder
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function backup(): void
|
2020-12-04 15:28:18 +03:00
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
$this->instance->backup($GLOBALS['argv'][3] ?? null);
|
2020-12-04 15:28:18 +03:00
|
|
|
}
|
|
|
|
|
2020-09-23 12:24:20 +03:00
|
|
|
/**
|
|
|
|
* Trigger the synchronization of all provider calendars with Google Calendar.
|
|
|
|
*
|
|
|
|
* Use this method in a cronjob to automatically sync events between Easy!Appointments and Google Calendar.
|
|
|
|
*
|
|
|
|
* Notice:
|
|
|
|
*
|
|
|
|
* Google syncing must first be enabled for each individual provider from inside the backend calendar page.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* php index.php console sync
|
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function sync(): void
|
2020-09-23 12:24:20 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$providers = $this->providers_model->get();
|
2020-09-23 12:24:20 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
foreach ($providers as $provider) {
|
|
|
|
if (!filter_var($provider['settings']['google_sync'], FILTER_VALIDATE_BOOLEAN)) {
|
2020-09-23 12:24:20 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
Google::sync((string) $provider['id']);
|
2020-09-23 12:24:20 +03:00
|
|
|
}
|
|
|
|
}
|
2020-12-05 12:03:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show help information about the console capabilities.
|
|
|
|
*
|
|
|
|
* Use this method to see the available commands.
|
|
|
|
*
|
|
|
|
* Usage:
|
|
|
|
*
|
|
|
|
* php index.php console help
|
|
|
|
*/
|
2024-04-26 17:36:14 +03:00
|
|
|
public function help(): void
|
2020-12-05 12:03:12 +03:00
|
|
|
{
|
|
|
|
$help = [
|
|
|
|
'',
|
|
|
|
'Easy!Appointments ' . config('version'),
|
|
|
|
'',
|
|
|
|
'Usage:',
|
|
|
|
'',
|
|
|
|
'⇾ php index.php console [command] [arguments]',
|
|
|
|
'',
|
|
|
|
'Commands:',
|
|
|
|
'',
|
|
|
|
'⇾ php index.php console migrate',
|
|
|
|
'⇾ php index.php console migrate fresh',
|
2021-11-06 17:17:03 +03:00
|
|
|
'⇾ php index.php console migrate up',
|
|
|
|
'⇾ php index.php console migrate down',
|
2020-12-05 12:03:12 +03:00
|
|
|
'⇾ php index.php console seed',
|
|
|
|
'⇾ php index.php console install',
|
|
|
|
'⇾ php index.php console backup',
|
|
|
|
'⇾ php index.php console sync',
|
|
|
|
'',
|
2023-12-22 13:35:41 +03:00
|
|
|
'',
|
2020-12-05 12:03:12 +03:00
|
|
|
];
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
response(implode(PHP_EOL, $help));
|
2020-12-05 12:03:12 +03:00
|
|
|
}
|
2020-09-23 12:24:20 +03:00
|
|
|
}
|