function getCachedComponentHooks() { require_once MAX_PATH . '/lib/OA/Cache.php'; $oCache = new OA_Cache('Plugins', 'ComponentHooks'); $oCache->setFileNameProtection(false); return $oCache->load(true); }
function _loadFromCache($accountType) { $oCache = new OA_Cache('Menu', $accountType); $oCache->setFileNameProtection(false); $aMenu = $oCache->load(true); if (!is_array($aMenu)) { return false; } if ($aMenu['checkerPaths']) { foreach ($aMenu['checkerPaths'] as $path) { if (!@(include_once MAX_PATH . $path)) { return false; } } } return unserialize($aMenu['oMenu']); }
function test_cachePreferenceOptions() { $oExtension = new OX_Extension_Common(); $GLOBALS['_MAX']['CONF']['pluginPaths']['packages'] = '/lib/OX/Extension/tests/data/'; $GLOBALS['_MAX']['CONF']['pluginGroupComponents'] = array('testPlugin' => 1); $this->_backupCacheFile('PrefOptions_Plugins'); $oExtension->cachePreferenceOptions(); $oCache = new OA_Cache('Plugins', 'PrefOptions'); $oCache->setFileNameProtection(false); $aPrefOptions = $oCache->load(true); $this->assertIsA($aPrefOptions, 'array'); $this->assertEqual(count($aPrefOptions), 1); $this->assertTrue(isset($aPrefOptions['testPlugin'])); $this->assertTrue(isset($aPrefOptions['testPlugin']['value'])); $this->assertTrue(isset($aPrefOptions['testPlugin']['name'])); $this->assertTrue(isset($aPrefOptions['testPlugin']['perm'])); $this->assertEqual($aPrefOptions['testPlugin']['name'], 'testPlugin'); $this->assertEqual($aPrefOptions['testPlugin']['text'], 'Option Text'); $this->assertEqual($aPrefOptions['testPlugin']['value'], 'account-preferences-plugin.php?group=testPlugin'); $this->assertEqual(count($aPrefOptions['testPlugin']['perm']), 4); $this->_restoreCacheFile('PrefOptions_Plugins'); TestEnv::restoreConfig(); }
function getComponentsHookCache() { if (!isset($GLOBALS['_MAX']['ComponentHooks'])) { $oCache = new OA_Cache('Plugins', 'ComponentHooks'); $oCache->setFileNameProtection(false); $GLOBALS['_MAX']['ComponentHooks'] = $oCache->load(true); if ($GLOBALS['_MAX']['ComponentHooks'] === false) { require_once LIB_PATH . '/Plugin/PluginManager.php'; $oPluginManager = new OX_PluginManager(); $GLOBALS['_MAX']['ComponentHooks'] = $oPluginManager->getComponentHooks(); $oCache->save($GLOBALS['_MAX']['ComponentHooks']); } } return $GLOBALS['_MAX']['ComponentHooks']; }
function test_getListOfRegisteredComponentsForHook() { $GLOBALS['_MAX']['CONF']['pluginPaths']['packages'] = '/lib/OX/Plugin/tests/data/plugins/etc/'; $GLOBALS['_MAX']['CONF']['pluginPaths']['admin'] = '/lib/OX/Plugin/tests/data/www/admin/plugins/'; $GLOBALS['_MAX']['CONF']['plugins'] = array('testPluginPackage' => 1); $GLOBALS['_MAX']['CONF']['pluginGroupComponents'] = array('testPlugin' => 1); require_once LIB_PATH . '/Extension/ExtensionCommon.php'; //generate test cache $oExtension = new OX_Extension_Common(); $oExtension->cacheComponentHooks(); $aHooks = OX_Component::getListOfRegisteredComponentsForHook('duringTest'); $this->assertIsA($aHooks, 'array'); $this->assertEqual(count($aHooks), 1); $this->assertEqual($aHooks[0], 'admin:testPlugin:testPlugin'); //remove cache unset($GLOBALS['_MAX']['ComponentHooks']); $oCache = new OA_Cache('Plugins', 'ComponentHooks'); $oCache->setFileNameProtection(false); $oCache->clear(); //should auto regenerate cache $aHooks = OX_Component::getListOfRegisteredComponentsForHook('duringTest'); $this->assertIsA($aHooks, 'array'); $this->assertEqual(count($aHooks), 1); $this->assertEqual($aHooks[0], 'admin:testPlugin:testPlugin'); //cache file should be regenerated $aAllHooks = $oCache->load(); $this->assertEqual($aHooks, $aAllHooks['duringTest']); TestEnv::restoreConfig(); $oCache->clear(); }
/** * A method to launch and display the widget * * @param array $aParams The parameters array, usually $_REQUEST */ function display() { $conf = $GLOBALS['_MAX']['CONF']; if (!$conf['audit']['enabled']) { $this->oTpl->assign('screen', 'disabled'); $this->oTpl->assign('siteTitle', $GLOBALS['strCampaignAuditTrailSetup']); $this->oTpl->assign('siteUrl', MAX::constructUrl(MAX_URL_ADMIN, 'account-settings-debug.php')); } else { $oCache = new OA_Cache('campaignOverview', 'Widgets'); $aCache = $oCache->load(true); $aCampaign = array(); if (isset($aCache['maxItems'])) { if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN)) { foreach ($aCache['aAccounts'] as $aActions) { foreach ($aActions as $aAction) { $aCampaign[$aAction['auditid']] = $aAction; } } } else { $aAccountsId = OA_Permission::getOwnedAccounts(OA_Permission::getAccountId()); foreach ($aAccountsId as $accountId) { if (isset($aCache['aAccounts'][$accountId])) { foreach ($aCache['aAccounts'][$accountId] as $aAction) { $aCampaign[$aAction['auditid']] = $aAction; } } } } krsort($aCampaign); $aCampaign = array_slice($aCampaign, 0, $aCache['maxItems']); } if (count($aCampaign)) { $aActionMap = array('added' => $GLOBALS['strCampaignStatusAdded'], 'started' => $GLOBALS['strCampaignStatusStarted'], 'restarted' => $GLOBALS['strCampaignStatusRestarted'], 'completed' => $GLOBALS['strCampaignStatusExpired'], 'paused' => $GLOBALS['strCampaignStatusPaused'], 'deleted' => $GLOBALS['strCampaignStatusDeleted']); foreach ($aCampaign as $k => $v) { if (isset($aActionMap[$v['action']])) { $aCampaign[$k]['actionDesc'] = $aActionMap[$v['action']]; } } } else { // Check if the account has any campaign in its realm $doCampaigns = OA_Dal::factoryDO('campaigns'); if (!empty($aParam['account_id'])) { $doClients = OA_Dal::factoryDO('clients'); $doAgency = OA_Dal::factoryDO('agency'); $doAgency->account_id = $aParam['account_id']; $doClients->joinAdd($doAgency); $doCampaigns->joinAdd($doClients); } $doCampaigns->limit(1); $this->oTpl->assign('hasCampaigns', $doCampaigns->count()); if (OA_Permission::isAccount(OA_ACCOUNT_ADMIN)) { $this->oTpl->assign('isAdmin', true); } } $this->oTpl->assign('screen', 'enabled'); $this->oTpl->assign('aCampaign', $aCampaign); $this->oTpl->assign('siteUrl', MAX::constructURL(MAX_URL_ADMIN, 'advertiser-campaigns.php')); $this->oTpl->assign('baseUrl', MAX::constructURL(MAX_URL_ADMIN, 'campaign-edit.php')); } $this->oTpl->display(); }
/** * perform post-audit actions * * @param int $actionid * @param DataObjects_Campaigns $dataobjectOld * @param int $auditId */ function _postAuditTrigger($actionid, $dataobjectOld, $auditId) { $aActionMap = array(); $aActionMap[OA_ENTITY_STATUS_RUNNING][OA_ENTITY_STATUS_AWAITING] = 'started'; $aActionMap[OA_ENTITY_STATUS_RUNNING][''] = 'restarted'; $aActionMap[OA_ENTITY_STATUS_EXPIRED][''] = 'completed'; $aActionMap[OA_ENTITY_STATUS_PAUSED][''] = 'paused'; $aActionMap[OA_ENTITY_STATUS_AWAITING][''] = 'paused'; switch ($actionid) { case OA_AUDIT_ACTION_INSERT: $actionType = 'added'; case OA_AUDIT_ACTION_UPDATE: if (isset($this->status) && $this->status != $dataobjectOld->status) { if (isset($aActionMap[$this->status][$dataobjectOld->status])) { $actionType = $aActionMap[$this->status][$dataobjectOld->status]; } elseif (isset($aActionMap[$this->status][''])) { $actionType = $aActionMap[$this->status]['']; } } break; case OA_AUDIT_ACTION_DELETE: $actionType = 'deleted'; break; } if (isset($actionType)) { // Prepare action array $maxItems = 6; $aAction = array('campaignid' => $this->campaignid, 'name' => $this->campaignname, 'clientid' => $this->clientid, 'auditid' => $auditId, 'action' => $actionType); // Load cache require_once MAX_PATH . '/lib/OA/Cache.php'; $oCache = new OA_Cache('campaignOverview', 'Widgets'); $aCache = $oCache->load(true); if (!$aCache) { // No cache, initialise $aCache = array('maxItems' => $maxItems, 'aAccounts' => array()); } // Get owning account id $accountId = $this->doAudit->account_id; if (!isset($aCache['aAccounts'][$accountId])) { // No cached array for this account id, initialise $aCache['aAccounts'][$accountId] = array(); } // Add current action as first item array_unshift($aCache['aAccounts'][$accountId], $aAction); //if current campaign is deleted, delete campaignid in all messages concernig this campaign if ($actionType == 'deleted') { //var_dump($aCache['aAccounts'][$accountId]); foreach ($aCache['aAccounts'][$accountId] as $k => $v) { if ($v['campaignid'] == $aAction['campaignid']) { $aCache['aAccounts'][$accountId][$k]['campaignid'] = ""; } } } // Only store most recent $maxItems actions, rekeying the array $aCache['aAccounts'][$accountId] = array_slice($aCache['aAccounts'][$accountId], 0, $maxItems); // Save cache $oCache->save($aCache); } }
function testCacheDir() { $oCache = new OA_Cache('test', 'oxpTestCache'); $oCache->clear(); $result = $oCache->load(true); $this->assertFalse($result); $newCacheDir = dirname(__FILE__) . '/../data/'; $serverName = $_SERVER['HTTP_HOST']; $_SERVER['HTTP_HOST'] = 'myhost'; $oCache = new OA_Cache('test', 'oxpTestCache', null, $newCacheDir); $oCache->setFileNameProtection(false); $result = $oCache->load(true); $this->assertEqual('test', $result); $_SERVER['HTTP_HOST'] = $serverName; }
function _mergePluginOptions(&$aSections) { $oCache = new OA_Cache('Plugins', 'PrefOptions'); $oCache->setFileNameProtection(false); $aPrefOptions = $oCache->load(true); if (!empty($aPrefOptions)) { $aSections = array_merge($aSections, $aPrefOptions); } }