Beispiel #1
0
 /**
  * Saves some necessary data in the database.
  *
  * This method is called just once after tables are created.
  *
  * @return boolean Indicates if the data are saved to the database or not.
  */
 protected function prepopulateDatabase()
 {
     if (!($db = $this->getDatabase())) {
         return false;
     }
     // Create The First Administrator if needed
     try {
         list($count) = $db->query('SELECT COUNT(*) FROM {operator} WHERE vclogin = :login', array(':login' => 'admin'), array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM));
         if ($count == 0) {
             $db->query('INSERT INTO {operator} ( ' . 'vclogin, vcpassword, vclocalename, vccommonname, ' . 'vcavatar, vcemail, iperm ' . ') values ( ' . ':login, :pass, :local_name, :common_name, ' . ':avatar, :email, :permissions)', array(':login' => 'admin', ':pass' => md5(''), ':local_name' => 'Administrator', ':common_name' => 'Administrator', ':avatar' => '', ':email' => '', ':permissions' => 65535));
         }
     } catch (\Exception $e) {
         $this->errors[] = getlocal('Cannot create the first administrator. Error {0}', array($e->getMessage()));
         return false;
     }
     // Initialize chat revision counter if it is needed
     try {
         list($count) = $db->query('SELECT COUNT(*) FROM {revision}', null, array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM));
         if ($count == 0) {
             $db->query('INSERT INTO {revision} VALUES (:init_revision)', array(':init_revision' => 1));
         }
     } catch (\Exception $e) {
         $this->errors[] = getlocal('Cannot initialize chat revision sequence. Error {0}', array($e->getMessage()));
         return false;
     }
     // Set correct database structure version if needed
     try {
         list($count) = $db->query('SELECT COUNT(*) FROM {config} WHERE vckey = :key', array(':key' => 'dbversion'), array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM));
         if ($count == 0) {
             $db->query('INSERT INTO {config} (vckey, vcvalue) VALUES (:key, :value)', array(':key' => 'dbversion', ':value' => MIBEW_VERSION));
         }
     } catch (\Exception $e) {
         $this->errors[] = getlocal('Cannot store database structure version. Error {0}', array($e->getMessage()));
         return false;
     }
     // Generate Unique ID for Mibew Instance
     try {
         list($count) = $db->query('SELECT COUNT(*) FROM {config} WHERE vckey = :key', array(':key' => '_instance_id'), array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM));
         if ($count == 0) {
             $db->query('INSERT INTO {config} (vckey, vcvalue) VALUES (:key, :value)', array(':key' => '_instance_id', ':value' => Utils::generateInstanceId()));
         } else {
             // The option is already in the database. It seems that
             // something went wrong with the previous installation attempt.
             // Just update the instance ID.
             $db->query('UPDATE {config} SET vcvalue = :value WHERE vckey = :key', array(':key' => '_instance_id', ':value' => Utils::generateInstanceId()));
         }
     } catch (\Exception $e) {
         $this->errors[] = getlocal('Cannot store instance ID. Error {0}', array($e->getMessage()));
         return false;
     }
     return true;
 }
Beispiel #2
0
 /**
  * Performs all database updates needed for 2.1.0.
  *
  * @return boolean True if the updates have been applied successfully and
  * false otherwise.
  */
 protected function update20100()
 {
     $db = $this->getDatabase();
     if (!$db) {
         return false;
     }
     try {
         // Alter locale table.
         $db->query('ALTER TABLE {locale} ADD COLUMN name varchar(128) NOT NULL DEFAULT "" AFTER code');
         $db->query('ALTER TABLE {locale} ADD COLUMN rtl tinyint NOT NULL DEFAULT 0');
         $db->query('ALTER TABLE {locale} ADD COLUMN time_locale varchar(128) NOT NULL DEFAULT "en_US"');
         $db->query('ALTER TABLE {locale} ADD COLUMN date_format text');
         $db->query('ALTER TABLE {locale} ADD UNIQUE KEY code (code)');
         // Create a table for available updates.
         $db->query('CREATE TABLE {availableupdate} ( ' . 'id INT NOT NULL auto_increment PRIMARY KEY, ' . 'target varchar(255) NOT NULL, ' . 'version varchar(255) NOT NULL, ' . 'url text, ' . 'description text, ' . 'UNIQUE KEY target (target) ' . ') charset utf8 ENGINE=InnoDb');
         // Generate Unique ID of Mibew instance.
         $db->query('INSERT INTO {config} (vckey, vcvalue) VALUES (:key, :value)', array(':key' => '_instance_id', ':value' => Utils::generateInstanceId()));
     } catch (\Exception $e) {
         $this->errors[] = getlocal('Cannot update tables: {0}', $e->getMessage());
         return false;
     }
     try {
         // Store configs for available locales in the database.
         $locales = $db->query('SELECT localeid as id, code from {locale}', null, array('return_rows' => Database::RETURN_ALL_ROWS));
         $locales_info = get_locales();
         foreach ($locales as $row) {
             $id = $row['id'];
             $code = $row['code'];
             $info = (isset($locales_info[$code]) ? $locales_info[$code] : array()) + array('name' => $code, 'rtl' => false, 'time_locale' => 'en_US', 'date_format' => array('full' => '%d %B %Y, %H:%M', 'date' => '%d %B %Y', 'time' => '%H:%M'));
             $db->query('UPDATE {locale} SET ' . 'name = :name, rtl = :rtl, time_locale = :time_locale, ' . 'date_format = :date_format ' . 'WHERE localeid = :id', array(':id' => $id, ':name' => $info['name'], ':rtl' => $info['rtl'] ? 1 : 0, ':time_locale' => $info['time_locale'], ':date_format' => serialize($info['date_format'])));
         }
     } catch (\Exception $e) {
         $this->errors[] = getlocal('Cannot update content: {0}', $e->getMessage());
         return false;
     }
     return true;
 }