public static function setUpBeforeClass() { parent::setUpBeforeClass(); global $freeze; if ($freeze) { $schemaFile = sys_get_temp_dir() . '/autobuilt.sql'; $success = preg_match("/;dbname=([^;]+)/", Yii::app()->db->connectionString, $matches); // Not Coding Standard assert('$success == 1'); // Not Coding Standard $databaseName = $matches[1]; if (file_exists($schemaFile) && filesize($schemaFile) > 0) { system('mysql -u' . Yii::app()->db->username . ' -p' . Yii::app()->db->password . ' ' . $databaseName . " < {$schemaFile}"); } } RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); assert('RedBeanDatabase::isSetup()'); // Not Coding Standard GeneralCache::forgetAll(); if ($freeze) { RedBeanDatabase::freeze(); TestDatabaseUtil::deleteRowsFromAllTablesExceptLog(); } else { TestDatabaseUtil::deleteAllTablesExceptLog(); } Yii::app()->user->userModel = null; Yii::app()->user->clearStates(); //reset session. Yii::app()->language = Yii::app()->getConfigLanguageValue(); Yii::app()->timeZoneHelper->setTimeZone(Yii::app()->getConfigTimeZoneValue()); Yii::app()->timeZoneHelper->load(); //resets timezone Yii::app()->languageHelper->flushModuleLabelTranslationParameters(); }
public function tearDown() { RedBeanDatabase::close(); RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password, true); if (is_file($this->databaseBackupTestFile)) { unlink($this->databaseBackupTestFile); } }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); global $freeze; RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); assert('RedBeanDatabase::isSetup()'); // Not Coding Standard if ($freeze) { $schemaFile = sys_get_temp_dir() . '/autobuilt.sql'; $success = preg_match("/;dbname=([^;]+)/", Yii::app()->db->connectionString, $matches); // Not Coding Standard assert('$success == 1'); // Not Coding Standard $databaseName = $matches[1]; if (is_readable($schemaFile) && filesize($schemaFile) > 0) { $systemOutput = system('mysql -u' . Yii::app()->db->username . ' -p' . Yii::app()->db->password . ' ' . $databaseName . " < {$schemaFile}"); if ($systemOutput != null) { echo 'Loading schema using system command. Output: ' . $systemOutput . "\n\n"; } } else { echo "The schema file is not readable: {$schemaFile}. \n\n"; exit; } } CustomFieldData::forgetAllPhpCache(); GeneralCache::forgetAll(); BeanModelCache::forgetAll(); if ($freeze) { RedBeanDatabase::freeze(); TestDatabaseUtil::deleteRowsFromAllTablesExceptLog(); } else { TestDatabaseUtil::deleteAllTablesExceptLog(); } Yii::app()->user->userModel = null; Yii::app()->user->clearStates(); //reset session. Yii::app()->language = Yii::app()->getConfigLanguageValue(); Yii::app()->timeZoneHelper->setTimeZone(Yii::app()->getConfigTimeZoneValue()); Yii::app()->timeZoneHelper->load(); //resets timezone Yii::app()->languageHelper->flushModuleLabelTranslationParameters(); if (static::$activateDefaultLanguages) { Yii::app()->languageHelper->load(); Yii::app()->languageHelper->activateLanguagesForTesting(); Yii::app()->languageHelper->importMessagesForTesting(); } }
protected static function setupDatabaseConnection($force = false) { if (!RedBeanDatabase::isSetup() || $force) { RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); } }
public function testRun() { chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands'); $command = "php zurmocTest.php install {$this->temporaryDatabaseHostname} {$this->temporaryDatabaseName} "; $command .= "{$this->temporaryDatabaseUsername} {$this->temporaryDatabasePassword} {$this->temporaryDatabasePort} "; $command .= "{$this->superUserPassword} 'http://sampleHost' 'app/index.php' demodata 1"; if (!IS_WINNT) { $command .= ' 2>&1'; } exec($command, $output); $instanceRoot = INSTANCE_ROOT; $perInstanceConfigFile = "{$instanceRoot}/protected/config/perInstanceTest.php"; $debugConfigFile = "{$instanceRoot}/protected/config/debugTest.php"; $perInstanceConfiguration = file_get_contents($perInstanceConfigFile); $debugConfiguration = file_get_contents($debugConfigFile); //Check if config files is updated. $this->assertRegExp('/\\$connectionString = \'mysql:host=' . $this->temporaryDatabaseHostname . ';port=' . $this->temporaryDatabasePort . ';dbname=' . $this->temporaryDatabaseName . '\';/', $perInstanceConfiguration); $this->assertRegExp('/\\$username = \'' . $this->temporaryDatabaseUsername . '\';/', $perInstanceConfiguration); $this->assertRegExp('/\\$password = \'' . $this->temporaryDatabasePassword . '\';/', $perInstanceConfiguration); RedBeanDatabase::close(); RedBeanDatabase::setup(Yii::app()->tempDb->connectionString, Yii::app()->tempDb->username, Yii::app()->tempDb->password, true); $count = R::getRow('select count(*) count from _user'); $this->assertEquals(9, $count['count']); }
protected static function reconnectToDatabase() { RedBeanDatabase::close(); RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); }
/** * Connects to the database. */ public static function connectToDatabase($databaseType, $host, $databaseName, $username, $password, $port) { assert('in_array($databaseType, static::getSupportedDatabaseTypes())'); assert('is_string($host) && $host != ""'); assert('is_string($databaseName) && $databaseName != ""'); assert('is_string($username) && $username != ""'); assert('is_string($password)'); $connectionString = "{$databaseType}:host={$host};port={$port};dbname={$databaseName}"; // Not Coding Standard RedBeanDatabase::setup($connectionString, $username, $password); }
public function handleSetupDatabaseConnection($event) { RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); if (!Yii::app()->isApplicationInstalled()) { throw new NotSupportedException(); } }
* * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the Zurmo * logo and Zurmo copyright notice. If the display of the logo is not reasonably * feasible for technical reasons, the Appropriate Legal Notices must display the words * "Copyright Zurmo Inc. 2014. All rights reserved". ********************************************************************************/ require_once '../../config/debug.php'; require_once '../common/bootstrap.php'; if (!($argc == 1 || $argc == 3 && $argv[1] == '-n' && is_numeric($argv[2]))) { echo "\nAuditLog - Displays the audit log.\nUsage: php AuditLog.php [-n #]\nOptions: -n # Displays the tail of the log up to # entries.\n"; exit; } $count = $argc == 3 ? intval($argv[2]) : null; try { RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); } catch (Exception $e) { echo "Could not open the database.\n"; exit; } try { Yii::app()->user->userModel = User::getByUsername('super'); } catch (Exception $e) { echo "Super user does not exist.\n"; exit; } $AuditEventsList = $count === null ? AuditEvent::getAll() : AuditEvent::getTailEvents($count); foreach ($AuditEventsList as $auditEvent) { $moduleName = $auditEvent->moduleName; echo $moduleName::stringifyAuditEvent($auditEvent) . "\n"; }
/** * Connects to the database with a connection string. */ public static function connectToDatabaseWithConnectionString($connectionString, $username, $password) { assert('is_string($connectionString) && $connectionString != ""'); assert('is_string($username) && $username != ""'); assert('is_string($password)'); RedBeanDatabase::setup($connectionString, $username, $password); assert('RedBeanDatabase::isSetup()'); }
/** * Added forgetAllCaches in case you are debugging and want to run this action again with a saved db. */ public function actionInstallDemoData() { RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password); InstallUtil::freezeDatabase(); ForgetAllCacheUtil::forgetAllCaches(); Yii::app()->user->userModel = User::getByUsername('super'); $nextView = new InstallCompleteView($this->getId(), $this->getModule()->getId()); $view = new InstallPageView($nextView); echo $view->render(); $template = ZurmoHtml::script("\$('#logging-table').prepend('{message}<br/>');"); $messageStreamer = new MessageStreamer($template); $messageStreamer->add(Zurmo::t('InstallModule', 'Starting to load demo data.')); $messageLogger = new MessageLogger($messageStreamer); DemoDataUtil::load($messageLogger, 6); $messageStreamer->add(Zurmo::t('InstallModule', 'Finished loading demo data.')); $messageStreamer->add(Zurmo::t('InstallModule', 'Locking Installation.')); InstallUtil::writeInstallComplete(INSTANCE_ROOT); ForgetAllCacheUtil::forgetAllCaches(); echo ZurmoHtml::script('$("#progress-table").hide(); $("#complete-table").show();'); }
public function tearDown() { RedBeanDatabase::close(); RedBeanDatabase::setup(Yii::app()->db->connectionString, Yii::app()->db->username, Yii::app()->db->password, true); }