Added a seed and installation command.

This commit is contained in:
Alex Tselegidis 2020-12-04 12:49:57 +02:00
parent 8570bd06c9
commit 76379ede44

View file

@ -11,7 +11,7 @@
* @since v1.3.2
* ---------------------------------------------------------------------------- */
require_once __DIR__ .'/Google.php';
require_once __DIR__ . '/Google.php';
/**
* Class Console
@ -32,7 +32,11 @@ class Console extends EA_Controller {
parent::__construct();
$this->load->library('migration');
$this->load->model('admins_model');
$this->load->model('customers_model');
$this->load->model('providers_model');
$this->load->model('services_model');
$this->load->model('settings_model');
}
/**
@ -49,6 +53,8 @@ class Console extends EA_Controller {
*
* php index.php console migrate
*
* php index.php console migrate fresh
*
* @param string $type
*/
public function migrate($type = '')
@ -64,6 +70,92 @@ class Console extends EA_Controller {
}
}
/**
* Seed the database with test data.
*
* Use this method to add test data to your database
*
* Usage:
*
* php index.php console seed
*/
public function seed()
{
// Settings
$this->settings_model->set_setting('company_name', 'Company Name');
$this->settings_model->set_setting('company_email', 'info@example.org');
$this->settings_model->set_setting('company_link', 'https://example.org');
// Admin
$this->admins_model->add([
'first_name' => 'John',
'last_name' => 'Doe',
'email' => 'john@example.org',
'phone_number' => '+1 (000) 000-0000',
'settings' => [
'username' => 'administrator',
'password' => 'administrator',
'notifications' => FALSE,
'calendar_view' => CALENDAR_VIEW_DEFAULT
],
]);
// Service
$service_id = $this->services_model->add([
'name' => 'Service',
'duration' => '30',
'price' => '0',
'currency' => '',
'availabilities_type' => 'flexible',
'attendants_number' => '1'
]);
// Provider
$this->providers_model->add([
'first_name' => 'Jane',
'last_name' => 'Doe',
'email' => 'jane@example.org',
'phone_number' => '+1 (000) 000-0000',
'services' => [
$service_id
],
'settings' => [
'username' => 'janedoe',
'password' => 'janedoe',
'working_plan' => $this->settings_model->get_setting('company_working_plan'),
'notifications' => FALSE,
'google_sync' => FALSE,
'sync_past_days' => 5,
'sync_future_days' => 5,
'calendar_view' => CALENDAR_VIEW_DEFAULT
],
]);
// Customer
$this->customers_model->add([
'first_name' => 'James',
'last_name' => 'Doe',
'email' => 'james@example.org',
'phone_number' => '+1 (000) 000-0000',
]);
}
/**
* Perform a console installation.
*
* Use this method to install Easy!Appointments directly from the terminal.
*
* Usage:
*
* php index.php console install
*/
public function install()
{
$this->migrate('fresh');
$this->seed();
$this->output->set_output(PHP_EOL . '⇾ Installation completed, login with "administrator" / "administrator".' . PHP_EOL . PHP_EOL);
}
/**
* Trigger the synchronization of all provider calendars with Google Calendar.
*