public function __construct() { // add tokens $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mailer.host'; $token->value = serialize('localhost'); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mailer.port'; $token->value = serialize(587); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mailer.username'; $token->value = serialize('*****@*****.**'); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mailer.password'; $token->value = serialize('123456'); $token->allow_override = true; $token->save(); // clear cache __c()->delete('_configTokens'); }
public function __construct() { // create config table ORM::get_db()->query(" CREATE TABLE `_config` (\n `id` INT( 32 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n `key` VARCHAR( 255 ) NOT NULL UNIQUE ,\n `value` TEXT NOT NULL,\n `allow_override` TINYINT( 1 ) NOT NULL DEFAULT '0'\n ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_bin;"); // add tokens $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'migrations.version'; $token->value = serialize(0); $token->allow_override = false; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'migrations.autoMigrate'; $token->value = serialize(true); $token->allow_override = false; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mysql.error_mode'; $token->value = serialize('PDO::ERRMODE_EXCEPTION'); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'mysql.log'; $token->value = serialize(true); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'system.default_timezone'; $token->value = serialize('Europe/Zurich'); $token->allow_override = false; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'system.log_errors'; $token->value = serialize(true); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'system.display_errors'; $token->value = serialize(true); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'system.log_max_length'; $token->value = serialize(4096); $token->allow_override = true; $token->save(); $token = Model::factory('BacboxConfigModel')->create(); $token->key = 'system.error_log_name'; $token->value = serialize('php_errors.log'); $token->allow_override = true; $token->save(); ORM::get_db()->query(" CREATE TABLE `_session` (\n `id` INT( 32 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n `session_id` VARCHAR( 32 ) NOT NULL UNIQUE,\n `session_name` VARCHAR( 32 ) NOT NULL,\n `session_create` DATETIME NOT NULL ,\n `session_last_access` DATETIME NOT NULL ,\n `session_host` VARCHAR( 255 ) NOT NULL ,\n `session_data` TEXT NOT NULL\n ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_bin;"); $tokenn = Model::factory('BacboxConfigModel')->create(); $tokenn->key = 'sessions.name'; $tokenn->value = serialize('sid'); $tokenn->allow_override = true; $tokenn->save(); $tokenn = Model::factory('BacboxConfigModel')->create(); $tokenn->key = 'sessions.max_lifetime'; $tokenn->value = serialize(900); $tokenn->allow_override = true; $tokenn->save(); $tokenn = Model::factory('BacboxConfigModel')->create(); $tokenn->key = 'sessions.gc_probability'; $tokenn->value = serialize(10); $tokenn->allow_override = true; $tokenn->save(); $tokenn = Model::factory('BacboxConfigModel')->create(); $tokenn->key = 'sessions.gc_divisor'; $tokenn->value = serialize(100); $tokenn->allow_override = true; $tokenn->save(); ORM::get_db()->query(" CREATE TABLE `_host` (\n `id` INT( 32 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n `host_regex` VARCHAR( 255 ) NOT NULL UNIQUE,\n `host_namespace` VARCHAR( 255 ) NOT NULL UNIQUE,\n `compute_order` SMALLINT NOT NULL DEFAULT '0'\n ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_bin;"); $host = Model::factory('BacboxHostModel')->create(); $host->host_regex = '*'; $host->host_namespace = 'sample'; $host->compute_order = 0; $host->save(); ORM::get_db()->query(" CREATE TABLE `_site` (\n `id` INT( 32 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n `host_id` INT( 32 ) NOT NULL,\n `site_regex` VARCHAR( 255 ) NOT NULL,\n `site_namespace` VARCHAR( 32 ) NOT NULL,\n `site_active` TINYINT ( 1 ) NOT NULL DEFAULT '1',\n `site_default_controller` VARCHAR( 32 ) NOT NULL,\n `site_multi_language` TINYINT ( 1 ) NOT NULL DEFAULT '1',\n `site_default_language` VARCHAR ( 2 ) DEFAULT 'en',\n `site_auto_migrate` TINYINT( 1 ) NOT NULL DEFAULT '1',\n `site_migrate_version` INT( 6 ) NOT NULL DEFAULT '0'\n ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_bin;"); $site = Model::factory('BacboxSiteModel')->create(); $site->host_id = 1; $site->site_regex = '*'; $site->site_namespace = 'sample'; $site->site_active = true; $site->site_default_controller = 'sample'; $site->site_multi_language = false; $site->site_default_language = ''; $site->save(); ORM::get_db()->query(" CREATE TABLE `_siteconfig` (\n `id` INT( 32 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n `site_id` INT( 32 ) NOT NULL,\n `key` VARCHAR ( 255 ) NOT NULL,\n `value` TEXT NOT NULL\n ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_bin;"); ORM::get_db()->query(" CREATE TABLE `_translation` (\n `id` INT( 32 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,\n `site_id` INT ( 32 ) NOT NULL,\n `language_alias` VARCHAR( 2 ) NOT NULL\n ) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_bin;"); }
/** * store token $key in persistance layer and assign value $value */ public static function store($key, $value) { // serialize the value to make it pretty for the database $value = serialize($value); $token = Model::factory('BacboxConfigModel')->where('key', $key)->find_one(); if ($token) { $token->key = $key; $token->value = $value; $token->save(); } else { $newToken = Model::factory('BacboxConfigModel')->create(); $newToken->key = $key; $newToken->value = $value; $newToken->save(); } }