/** * A helper method to set applicationvariables * * @param Date $oScheduledDate * @param Date $oDate */ function setVariables($oScheduledDate, $oDate) { if (isset($oScheduledDate)) { OA_Dal_ApplicationVariables::set('maintenance_cron_timestamp', $oScheduledDate->getDate(DATE_FORMAT_UNIXTIME)); } else { OA_Dal_ApplicationVariables::delete('maintenance_cron_timestamp'); } if (isset($oDate)) { OA_Dal_ApplicationVariables::set('maintenance_timestamp', $oDate->getDate(DATE_FORMAT_UNIXTIME)); } else { OA_Dal_ApplicationVariables::delete('maintenance_timestamp'); } }
/** * Update checkForUpdates value into Settings * * @param boolean $syncEnabled * @return boolean */ function putSyncSettings($syncEnabled) { require_once MAX_PATH . '/lib/OA/Admin/Settings.php'; require_once MAX_PATH . '/lib/OA/Sync.php'; $oSettings = new OA_Admin_Settings(); $oSettings->settingChange('sync', 'checkForUpdates', $syncEnabled); // Reset Sync cache OA_Dal_ApplicationVariables::delete('sync_cache'); OA_Dal_ApplicationVariables::delete('sync_timestamp'); OA_Dal_ApplicationVariables::delete('sync_last_seen'); if (!$oSettings->writeConfigChange()) { $this->oLogger->logError('Error saving Sync settings to the config file'); return false; } // Generate a new Platform Hash if empty $platformHash = OA_Dal_ApplicationVariables::get('platform_hash'); if (empty($platformHash) && !OA_Dal_ApplicationVariables::set('platform_hash', OA_Dal_ApplicationVariables::generatePlatformHash())) { $this->oLogger->logError('Error inserting Platform Hash into database'); return false; } $oSync = new OA_Sync(); OA::disableErrorHandling(); $oSync->checkForUpdates(); OA::enableErrorHandling(); return true; }
/** * Test delete * */ function testDelete() { $result = OA_Dal_ApplicationVariables::delete('foo'); $this->assertFalse($result); }
function testGetLastRun() { $oMaintenance = new OX_Maintenance(); $this->assertNull($oMaintenance->getLastRun()); $iLastRun = strtotime('2002-01-01'); OA_Dal_ApplicationVariables::set('maintenance_timestamp', $iLastRun); $oDate = new Date((int) $iLastRun); $this->assertTrue($oDate->equals($oMaintenance->getLastRun())); OA_Dal_ApplicationVariables::delete('maintenance_timestamp'); }
function testPutAdmin() { $oUpgrade = new OA_Upgrade(); // Prepare test data $aAdmin = array('email' => '*****@*****.**', 'name' => 'testadmin', 'pword' => 'testpass', 'language' => 'es'); $aPrefs = array('timezone' => 'Europe/Madrid'); // there shouldn't be admin account $adminAccountId = OA_Dal_ApplicationVariables::get('admin_account_id'); $this->assertNull($adminAccountId); // create admin $result = $oUpgrade->putAdmin($aAdmin, $aPrefs); $this->assertTrue($result); // admin account is set $adminAccountId = OA_Dal_ApplicationVariables::get('admin_account_id'); $this->assertNotNull($adminAccountId); $doAccount = OA_Dal::factoryDO('accounts'); $doAccount->get($adminAccountId); $this->assertEqual($doAccount->account_type, OA_ACCOUNT_ADMIN); $this->assertEqual($doAccount->account_name, 'Administrator account'); // user exists $doUser = OA_Dal::factoryDO('users'); $doUserAssoc = OA_Dal::factoryDO('account_user_assoc'); $doUserAssoc->account_id = $adminAccountId; $doUser->joinAdd($doUserAssoc); $doUser->find(); $this->assertTrue($doUser->fetch()); $this->assertEqual($doUser->contact_name, 'Administrator'); $this->assertEqual($doUser->email_address, $aAdmin['email']); $this->assertEqual($doUser->username, $aAdmin['name']); $this->assertEqual($doUser->password, md5($aAdmin['pword'])); $this->assertEqual($doUser->language, $aAdmin['language']); // agency was created $doAgency = OA_Dal::factoryDO('agency'); $doAccount = OA_Dal::factoryDO('accounts'); $doAccount->account_id = $doUser->default_account_id; $doAgency->joinAdd($doAccount); $doAgency->find(); $this->assertTrue($doAgency->fetch()); $this->assertEqual($doAgency->name, 'Default manager'); $this->assertEqual($doAgency->email, $aAdmin['email']); $this->assertEqual($doAgency->active, 1); // Default preferences + custom timezone are set $oPreferences = new OA_Preferences(); $aDefPrefs = $oPreferences->getPreferenceDefaults(); $aExpected = array(); foreach ($aDefPrefs as $name => $values) { $aExpected[$name] = $values['default']; } $aExpected['timezone'] = $aPrefs['timezone']; $aExpected['language'] = 'en'; //added by get admin account preferences $aAdminPreferences = OA_Preferences::loadAdminAccountPreferences(true); $this->assertEqual($aExpected, $aAdminPreferences); // trunkate tables DataGenerator::cleanUp(array('account_preference_assoc', 'preferences', 'account_user_assoc', 'users', 'agency', 'accounts')); // remove admin_account_id from application variables OA_Dal_ApplicationVariables::delete('admin_account_id'); }
/** * MyISAM has no transaction, so we are reverting changes by truncating tables * Assuming that this is install step and we have empty database! * * @param int $adminAccountId * @param int $agencyId * @param int $userId * @param bool $deletePreferences */ protected function _rollbackPutAdmin() { // delete from account_preference_assoc $doPreferencesAssoc = OA_Dal::factoryDO('account_preference_assoc'); $doPreferencesAssoc->whereAdd('1=1'); $doPreferencesAssoc->delete(DB_DATAOBJECT_WHEREADD_ONLY); // delete from preferences $doPreferences = OA_Dal::factoryDO('preferences'); $doPreferences->whereAdd('1=1'); $doPreferences->delete(DB_DATAOBJECT_WHEREADD_ONLY); // delete from account_user_assoc $doUserAssoc = OA_Dal::factoryDO('account_user_assoc'); $doUserAssoc->whereAdd('1=1'); $doUserAssoc->delete(DB_DATAOBJECT_WHEREADD_ONLY); // delete from users $doUser = OA_Dal::factoryDO('users'); $doUser->whereAdd('1=1'); $doUser->delete(DB_DATAOBJECT_WHEREADD_ONLY); // delete from agency $doAgency = OA_Dal::factoryDO('agency'); $doAgency->whereAdd('1=1'); $doAgency->delete(DB_DATAOBJECT_WHEREADD_ONLY); // delete from accounts $doAccount = OA_Dal::factoryDO('accounts'); $doAccount->whereAdd('1=1'); $doAccount->delete(DB_DATAOBJECT_WHEREADD_ONLY); // remove admin_account_id from application variables OA_Dal_ApplicationVariables::delete('admin_account_id'); }
require_once MAX_PATH . '/lib/OA/Upgrade/Upgrade.php'; require_once MAX_PATH . '/lib/OA/Upgrade/Login.php'; if (array_key_exists('btn_openads', $_POST) || OA_INSTALLATION_STATUS == OA_INSTALLATION_STATUS_INSTALLED) { require_once MAX_PATH . '/lib/max/other/lib-io.inc.php'; require_once MAX_PATH . '/lib/OA/Sync.php'; // The opt box is ticked... if (!empty($_POST['signup_opt'])) { if (!empty($_POST['signup_email'])) { phpAds_registerGlobalUnslashed('signup_email'); OA_Dal_ApplicationVariables::set('sync_registered_email', $signup_email); $oSync = new OA_Sync(); $res = $oSync->checkForUpdates(); } } else { // The opt button is unticked, clear any existing sync_registered_email OA_Dal_ApplicationVariables::delete('sync_registered_email'); } require_once LIB_PATH . '/Admin/Redirect.php'; OX_Admin_Redirect::redirect('advertiser-index.php'); } // Setup oUpgrader $oUpgrader = new OA_Upgrade(); @set_time_limit(600); // required files for header & nav require_once MAX_PATH . '/lib/max/Admin/Languages.php'; require_once MAX_PATH . '/lib/OA/Permission.php'; require_once MAX_PATH . '/www/admin/lib-gui.inc.php'; require_once MAX_PATH . '/lib/OA/Admin/Template.php'; require_once MAX_PATH . '/lib/OA/Admin/Option.php'; require_once MAX_PATH . '/lib/max/language/Loader.php'; require_once MAX_PATH . '/lib/OA/Upgrade/UpgradePluginImport.php';