public function getPlugin($gateway_id) { if (null === $this->_plugin) { if (null == ($gateway = Engine_Api::_()->getItem('payment_gateway', $gateway_id))) { return null; } Engine_Loader::loadClass($gateway->plugin); if (!class_exists($gateway->plugin)) { return null; } if (in_array($gateway->title, array('Authorize.Net', 'iTransact'))) { $class = str_replace('Ynpayment', 'Ynsocialads', $gateway->plugin); } else { $class = str_replace('Payment', 'Ynsocialads', $gateway->plugin); } Engine_Loader::loadClass($class); if (!class_exists($class)) { return null; } $plugin = new $class($gateway); if (!$plugin instanceof Engine_Payment_Plugin_Abstract) { throw new Engine_Exception(sprintf('Payment plugin "%1$s" must ' . 'implement Engine_Payment_Plugin_Abstract', $class)); } $this->_plugin = $plugin; } return $this->_plugin; }
public function getForm() { if (is_null($this->_form)) { $formArgs = array(); // Preload profile type field stuff $profileTypeField = $this->getProfileTypeField(); if ($profileTypeField) { $accountSession = new Zend_Session_Namespace('User_Plugin_Signup_Account'); $profileTypeValue = @$accountSession->data['profile_type']; if ($profileTypeValue) { $formArgs = array('topLevelId' => $profileTypeField->field_id, 'topLevelValue' => $profileTypeValue); } } // Create form Engine_Loader::loadClass($this->_formClass); $class = $this->_formClass; $this->_form = new $class($formArgs); $data = $this->getSession()->data; if (empty($data)) { $fb_session = new Zend_Session_Namespace('User_AuthController'); $data = $fb_session->data; } if (!empty($data)) { foreach ($data as $key => $val) { $el = $this->_form->getElement($key); if ($el) { $el->setValue($val); } } } } return $this->_form; }
public function getJobPlugin($job, $jobType = null) { // Must be a row of jobs if (!is_object($job)) { throw new Core_Model_Exception(sprintf('Must be given a row of ' . 'Core_Model_DbTable_Jobs, given ' . '%s', gettype($job))); } else { if (!$job->getTable() instanceof Core_Model_DbTable_Jobs) { throw new Core_Model_Exception(sprintf('Must be given a row of ' . 'Core_Model_DbTable_Jobs, given ' . '%s', get_class($job))); } } // Get job type if missing if (null === $jobType) { $jobType = $this->find($job->jobtype_id)->current(); } // Get plugin class $class = $jobType->plugin; // Load class Engine_Loader::loadClass($class); // Make sure is a subclass of Core_Plugin_Task_Abstract if (!is_subclass_of($class, 'Core_Plugin_Job_Abstract')) { throw new Core_Model_Exception(sprintf('Job plugin %1$s should extend Core_Plugin_Job_Abstract', $class)); } // Check for execute method? if (!method_exists($class, 'execute')) { throw new Core_Model_Exception(sprintf('Job plugin %1$s does not have an execute method', $class)); } // Get plugin object $plugin = new $class($job, $jobType); // Set the log $plugin->setLog($this->getLog()); return $plugin; }
public function getItemTable($type) { if ($type == 'event_album') { return Engine_Loader::getInstance()->load('Ynevent_Model_DbTable_Albums'); } else { if ($type == 'event_category') { return Engine_Loader::getInstance()->load('Ynevent_Model_DbTable_Categories'); } else { if ($type == 'event_post') { return Engine_Loader::getInstance()->load('Ynevent_Model_DbTable_Posts'); } else { if ($type == 'event_topic') { return Engine_Loader::getInstance()->load('Ynevent_Model_DbTable_Topics'); } else { if ($type == 'event_photo') { return Engine_Loader::getInstance()->load('Ynevent_Model_DbTable_Photos'); } else { if ($type == 'event_sponsor') { return Engine_Loader::getInstance()->load('Ynevent_Model_DbTable_Sponsors'); } else { if ($type == 'event_agent') { return Engine_Loader::getInstance()->load('Ynevent_Model_DbTable_Agents'); } else { $class = Engine_Api::_()->getItemTableClass($type); return Engine_Api::_()->loadClass($class); } } } } } } } }
public function getStorage() { if (is_null($this->_storage)) { Engine_Loader::loadClass('File_Model_Storage'); $this->_storage = File_Model_Storage::getInstance(); } return $this->_storage; }
public static function factory($itemType, $tableType, $config = array()) { if (!is_string($itemType) || !is_string($tableType)) { throw new Fields_Model_Exception('Item type and table type must be strings'); } $class = 'Fields_Model_DbTable_' . ucfirst($tableType); Engine_Loader::loadClass($class); return new $class($itemType, $tableType, $config); }
public function getItemTable($type) { if ($type == 'group') { return Engine_Loader::getInstance()->load('Advgroup_Model_DbTable_Groups'); } else { $class = Engine_Api::_()->getItemTableClass($type); return Engine_Api::_()->loadClass($class); } }
/** * Gets a session namespace unique to this controller * * @return Zend_Session_Namespace */ public function getSession() { if (is_null($this->_session)) { Engine_Loader::loadClass('Zend_Session_Namespace'); $namespace = get_class($this); $this->_session = new Zend_Session_Namespace($namespace); } return $this->_session; }
public static function factory(Zend_Db_Adapter_Abstract $adapter, $options = array()) { list($prefix, $type) = explode('_Db_Adapter_', get_class($adapter)); $class = 'Engine' . '_Db_Export_' . $type; Engine_Loader::loadClass($class); $instance = new $class($adapter, $options); if (!$instance instanceof Engine_Db_Export) { throw new Engine_Exception('Must be an instance of Engine_Db_Export'); } return $instance; }
public function getGateway() { if (null === $this->_gateway) { $class = 'Engine_Payment_Gateway_2Checkout'; Engine_Loader::loadClass($class); $gateway = new $class(array('config' => (array) $this->_gatewayInfo->config, 'testMode' => $this->_gatewayInfo->test_mode, 'currency' => Engine_Api::_()->getApi('settings', 'core')->getSetting('payment.currency', 'USD'))); if (!$gateway instanceof Engine_Payment_Gateway) { throw new Engine_Exception('Plugin class not instance of Engine_Payment_Gateway'); } $this->_gateway = $gateway; } return $this->_gateway; }
public function getItemTable($type) { if ($type == 'blog_category') { return Engine_Loader::getInstance()->load('Ynblog_Model_DbTable_Categories'); } else { if ($type == 'blog') { return Engine_Loader::getInstance()->load('Ynblog_Model_DbTable_Blogs'); } else { $class = Engine_Api::_()->getItemTableClass($type); return Engine_Api::_()->loadClass($class); } } }
/** * Get the payment plugin * * @return Engine_Payment_Plugin_Abstract */ public function getPlugin() { if (null === $this->_plugin) { $class = $this->plugin; Engine_Loader::loadClass($class); $plugin = new $class($this); if (!$plugin instanceof Engine_Payment_Plugin_Abstract) { throw new Engine_Exception(sprintf('Payment plugin "%1$s" must ' . 'implement Engine_Payment_Plugin_Abstract', $class)); } $this->_plugin = $plugin; } return $this->_plugin; }
/** * Factory method for VFS * * @param string $adapter * @param array $config * @return Engine_Vfs_Adapter_Interface */ public static function factory($adapter, array $config = array()) { $classPrefix = 'Engine_Vfs_Adapter_'; if (isset($config['adapterPrefix'])) { $classPrefix = rtrim($config['adapterPrefix'], '_') . ')'; } $class = $classPrefix . ucfirst($adapter); Engine_Loader::loadClass($class); if (!is_subclass_of($class, 'Engine_Vfs_Adapter_Interface')) { throw new Engine_Vfs_Exception('Adapter class must extend Engine_Vfs_Adapter_Interface'); } $instance = new $class($config); return $instance; }
public function getAdminForm() { if (is_null($this->_adminForm)) { Engine_Loader::loadClass($this->_adminFormClass); $class = $this->_adminFormClass; $this->_adminForm = new $class(); $data = $this->getSession()->data; if (!empty($data)) { foreach ($data as $key => $val) { $el = $this->_adminForm->getElement($key); if ($el) { $el->setValue($val); } } } } return $this->_adminForm; }
public function __construct($options) { if ($options instanceof Zend_Config) { $options = $options->toArray(); } if (!is_array($options)) { // require_once 'Zend/Loader/Exception.php'; throw new Zend_Loader_Exception('Options must be passed to resource loader constructor'); } $this->setOptions($options); $namespace = $this->getNamespace(); if (null === $namespace || null === $this->getBasePath()) { // require_once 'Zend/Loader/Exception.php'; throw new Zend_Loader_Exception('Resource loader requires both a namespace and a base path for initialization'); } if (!empty($namespace)) { $namespace .= '_'; } Engine_Loader::getInstance()->register(trim($namespace, '_'), $this->getBasePath()); //Zend_Loader_Autoloader::getInstance()->unshiftAutoloader($this, $namespace); }
public function getForm() { $formArgs = array(); // Preload profile type field stuff $profileTypeField = $this->getProfileTypeField(); if ($profileTypeField) { $accountSession = new Zend_Session_Namespace('User_Plugin_Signup_Account'); $profileTypeValue = @$accountSession->data['profile_type']; if ($profileTypeValue) { $formArgs = array('topLevelId' => $profileTypeField->field_id, 'topLevelValue' => $profileTypeValue); } else { $topStructure = Engine_Api::_()->fields()->getFieldStructureTop('user'); if (count($topStructure) == 1 && $topStructure[0]->getChild()->type == 'profile_type') { $profileTypeField = $topStructure[0]->getChild(); $options = $profileTypeField->getOptions(); if (count($options) == 1) { $formArgs = array('topLevelId' => $profileTypeField->field_id, 'topLevelValue' => $options[0]->option_id); } } } } // Create form Engine_Loader::loadClass($this->_formClass); $class = $this->_formClass; $this->_form = new $class($formArgs); $fieldsSession = new Zend_Session_Namespace('User_Plugin_Signup_Fields'); $this->setSession($fieldsSession); $data = $this->getSession()->data; if (!empty($data)) { foreach ($data as $key => $val) { $el = $this->_form->getElement($key); if ($el instanceof Zend_Form_Element) { $el->setValue($val); } } } return $this->_form; }
public function getService($serviceIdentity = null) { if (null === $serviceIdentity) { $serviceIdentity = $this->getDefaultServiceIdentity(); } else { if (!is_numeric($serviceIdentity)) { throw new Storage_Model_Exception('Invalid storage service identity specifier'); } } if (!isset($this->_services[$serviceIdentity])) { // Get service info $serviceInfo = $this->select()->where('service_id = ?', $serviceIdentity)->where('enabled = ?', 1)->limit(1)->query()->fetch(); if (!$serviceInfo) { throw new Storage_Model_Exception(sprintf('Missing storage service "%s"', $serviceIdentity)); } // Get service type info $serviceTypeIdentity = $serviceInfo['servicetype_id']; $serviceTypeInfo = Engine_Api::_()->getDbtable('serviceTypes', 'storage')->select()->where('servicetype_id = ?', $serviceTypeIdentity)->limit(1)->query()->fetch(); if (!$serviceTypeInfo) { throw new Storage_Model_Exception(sprintf('Missing storage service type "%s"', $serviceTypeIdentity)); } $class = $serviceTypeInfo['plugin']; Engine_Loader::loadClass($class); if (!class_exists($class, false) || !in_array('Storage_Service_Interface', class_implements($class))) { throw new Storage_Model_Exception(sprintf('Missing storage service ' . 'class or does not implement Storage_Service_Interface for ' . 'service "%s"', $serviceIdentity)); } $config = array(); if (!empty($serviceInfo['config'])) { $config = Zend_Json::decode($serviceInfo['config']); if (!is_array($config)) { $config = array(); } } $config['service_id'] = $serviceInfo['service_id']; $this->_services[$serviceIdentity] = new $class($config); } return $this->_services[$serviceIdentity]; }
public function __construct($application, $options = null) { // Set application $this->setApplication($application); // Set custom module options (for dynamic bootstrapping) if (is_array($options)) { $this->setOptions($options); } // Use same plugin loader as parent bootstrap if ($application instanceof Zend_Application_Bootstrap_ResourceBootstrapper) { $this->setPluginLoader($application->getPluginLoader()); } // Get the options from config $key = strtolower($this->getModuleName()); if ($application->hasOption($key)) { // Don't run via setOptions() to prevent duplicate initialization $this->setOptions($application->getOption($key)); } // Init resource loader if ($application->hasOption('resourceloader')) { $this->setOptions(array('resourceloader' => $application->getOption('resourceloader'))); } //$this->initResourceLoader(); Engine_Loader::getInstance()->register($this->getModuleName(), $this->getModulePath()); $isDefaultModule = get_class($this->getApplication()) === 'Zend_Application'; // ZF-6545: ensure front controller resource is loaded if (!$isDefaultModule && !$this->hasPluginResource('FrontController')) { $this->registerPluginResource('FrontController'); } // ZF-6545: prevent recursive registration of modules if (!$isDefaultModule && $this->hasPluginResource('Modules')) { $this->unregisterPluginResource('Modules'); } // Register with Engine_Api Engine_Api::_()->setModuleBootstrap($this); // Run internal hook $this->preBootstrap(); }
/** * Factory method. Automatically picks available adapter * * @param string $adapter Force this adapter * @param array $options * @return Engine_Image */ public static function factory($options = array(), $adapter = 'gd') { $hasGd = function_exists('gd_info'); $hasImagick = class_exists('Imagick', false); if (!$hasGd && !$hasImagick) { throw new Engine_Image_Exception('No available adapter for image operations'); } if (!($adapter == 'gd' && $hasGd) && !($adapter == 'imagick' && $hasImagick)) { if ($hasGd) { $adapter = 'gd'; } else { if ($hasImagick) { $adapter = 'imagick'; } } } $class = 'Engine_Image_Adapter_' . ucfirst($adapter); Engine_Loader::loadClass($class); if (!class_exists($class, false)) { throw new Engine_Image_Exception(sprintf('Missing class for adapter "%s"', $adapter)); } return new $class($options); }
public function editAction() { // Check params $justCreated = $this->_getParam('justCreated'); $serviceIdentity = $this->_getParam('service_id'); if (!$serviceIdentity) { return $this->_helper->redirector->gotoRoute(array('action' => 'index', 'service_id' => null, 'justCreated' => null)); } $serviceTable = Engine_Api::_()->getDbtable('services', 'storage'); $service = $serviceTable->find($serviceIdentity)->current(); if (!$service) { return $this->_helper->redirector->gotoRoute(array('action' => 'index', 'service_id' => null, 'justCreated' => null)); } $serviceTypesTable = Engine_Api::_()->getDbtable('serviceTypes', 'storage'); $serviceType = $serviceTypesTable->find($service->servicetype_id)->current(); if (!$serviceType) { return $this->_helper->redirector->gotoRoute(array('action' => 'index', 'service_id' => null, 'justCreated' => null)); } // Get form class if (!empty($serviceType['form'])) { $formClass = $serviceType['form']; } else { $formClass = 'Storage_Form_Admin_Service_Generic'; } Engine_Loader::loadClass($formClass); // Make form $this->view->form = $form = new $formClass(); $form->setTitle($this->view->translate('Edit Storage Service: %s (ID: %d)', $serviceType->title, $service->service_id)); // Populate form $config = null; if (!empty($service->config)) { $config = Zend_Json::decode($service->config); if (!is_array($config)) { $config = null; } else { $config = $this->_flattenParams($config); } } $form->populate($service->toArray()); if (!empty($config)) { $form->populate($config); } // Check method if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return; } // Process $values = $form->getValues(); $values = $this->_expandParams($values); $db = $serviceTable->getAdapter(); $db->beginTransaction(); try { $service->enabled = (bool) $values['enabled']; unset($values['enabled']); if (empty($values)) { $service->config = null; } else { $service->config = Zend_Json::encode($values); } $service->save(); $db->commit(); } catch (Exception $e) { $db->rollBack(); throw $e; } $form->addNotice('Your changes have been saved.'); }
public function addToArchive(Archive_Tar $archive) { // Add package file $rval = $archive->addString('application' . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . $this->getKey() . '.json', $this->toString('json')); if ($archive->isError($rval)) { throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage()); } // Add internal structure if ($this->getAddDirectoryToArchive()) { $rval = $archive->addModify($this->getBasePath() . DIRECTORY_SEPARATOR . $this->getPath(), null, $this->getBasePath()); if ($archive->isError($rval)) { throw new Engine_Package_Manifest_Exception('Error in archive: ' . $rval->getMessage()); } } else { foreach ($this->getStructure() as $key => $value) { if ($this->_jitInstantiation && is_array($value) && !empty($value['type'])) { $class = 'Engine_Package_Manifest_Entity_' . ucfirst($value['type']); Engine_Loader::loadClass($class); $value = new $class($value); $value->setBasePath($this->getBasePath()); } else { if (!$value instanceof Engine_Package_Manifest_Entity_Abstract) { throw new Engine_Package_Manifest_Exception('Not a package entity'); } } if (method_exists($value, 'setAddDirectoryToArchive')) { $value->setAddDirectoryToArchive($this->getAddDirectoryToArchive()); } $value->addToArchive($archive); } } }
public function widgetAction() { // Render by widget name $mod = $this->_getParam('mod'); $name = $this->_getParam('name'); if (null === $name) { throw new Exception('no widget found with name: ' . $name); } if (null !== $mod) { $name = $mod . '.' . $name; } $contentInfoRaw = $this->getContentAreas(); $contentInfo = array(); foreach ($contentInfoRaw as $info) { $contentInfo[$info['name']] = $info; } // It has a form specified in content manifest if (!empty($contentInfo[$name]['adminForm'])) { if (is_string($contentInfo[$name]['adminForm'])) { // Core_Form_Admin_Widget_* $formClass = $contentInfo[$name]['adminForm']; Engine_Loader::loadClass($formClass); $this->view->form = $form = new $formClass(); } else { if (is_array($contentInfo[$name]['adminForm'])) { $this->view->form = $form = new Engine_Form($contentInfo[$name]['adminForm']); } else { throw new Core_Model_Exception('Unable to load admin form class'); } } // Try to set title if missing if (!$form->getTitle()) { $form->setTitle('Editing: ' . $contentInfo[$name]['title']); } // Try to set description if missing if (!$form->getDescription()) { $form->setDescription('placeholder'); } $form->setAttrib('class', 'global_form_popup ' . $form->getAttrib('class')); // Add title element if (!$form->getElement('title')) { $form->addElement('Text', 'title', array('label' => 'Title', 'order' => -100)); } // Add mobile element? if (!$form->getElement('nomobile')) { $form->addElement('Select', 'nomobile', array('label' => 'Hide on mobile site?', 'order' => 100000 - 5, 'multiOptions' => array('1' => 'Yes, do not display on mobile site.', '0' => 'No, display on mobile site.'), 'value' => '0')); } if (!empty($contentInfo[$name]['isPaginated']) && !$form->getElement('itemCountPerPage')) { $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0))), 'order' => 1000000 - 1)); } // Add submit button if (!$form->getElement('submit') && !$form->getElement('execute')) { $form->addElement('Button', 'execute', array('label' => 'Save Changes', 'type' => 'submit', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000000)); } // Add name $form->addElement('Hidden', 'name', array('value' => $name, 'order' => 1000010)); if (!$form->getElement('cancel')) { $form->addElement('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1000001)); } if (!$form->getDisplayGroup('buttons')) { $submitName = $form->getElement('execute') ? 'execute' : 'submit'; $form->addDisplayGroup(array($submitName, 'cancel'), 'buttons', array('order' => 1000002)); } // Force method and action $form->setMethod('post')->setAction($_SERVER['REQUEST_URI']); if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $this->view->values = $form->getValues(); $this->view->form = null; } return; } // Try to render admin page if (!empty($contentInfo[$name])) { try { $structure = array('type' => 'widget', 'name' => $name, 'request' => $this->getRequest(), 'action' => 'admin', 'throwExceptions' => true); // Create element (with structure) $element = new Engine_Content_Element_Container(array('elements' => array($structure), 'decorators' => array('Children'))); $content = $element->render(); $this->getResponse()->setBody($content); $this->_helper->viewRenderer->setNoRender(true); return; } catch (Exception $e) { } } // Just render default editing form $this->view->form = $form = new Engine_Form(array('title' => $contentInfo[$name]['title'], 'description' => 'placeholder', 'method' => 'post', 'action' => $_SERVER['REQUEST_URI'], 'class' => 'global_form_popup', 'elements' => array(array('Text', 'title', array('label' => 'Title')), array('Button', 'submit', array('label' => 'Save', 'type' => 'submit', 'decorators' => array('ViewHelper'), 'ignore' => true, 'order' => 1501)), array('Hidden', 'name', array('value' => $name)), array('Cancel', 'cancel', array('label' => 'cancel', 'link' => true, 'prependText' => ' or ', 'onclick' => 'parent.Smoothbox.close();', 'ignore' => true, 'decorators' => array('ViewHelper'), 'order' => 1502))), 'displaygroups' => array('buttons' => array('name' => 'buttons', 'elements' => array('submit', 'cancel'), 'options' => array('order' => 1500))))); if (!empty($contentInfo[$name]['isPaginated'])) { $form->addElement('Text', 'itemCountPerPage', array('label' => 'Count', 'description' => '(number of items to show)', 'validators' => array(array('Int', true), array('GreaterThan', true, array(0))))); } if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $this->view->values = $form->getValues(); $this->view->form = null; } else { $form->populate($this->_getAllParams()); } }
define('_ENGINE_R_MAIN', 'mobile.php'); define('_ENGINE_R_INIT', true); } else { define('_ENGINE_R_MAIN', false); define('_ENGINE_R_INIT', true); } } } } } // Boot if (_ENGINE_R_INIT) { // Application require_once 'Engine/Loader.php'; require_once 'Engine/Application.php'; Engine_Loader::getInstance()->register('Zend', APPLICATION_PATH_COR . DS . 'libraries' . DS . 'Zend')->register('Engine', APPLICATION_PATH_COR . DS . 'libraries' . DS . 'Engine')->register('Facebook', APPLICATION_PATH_COR . DS . 'libraries' . DS . 'Facebook')->register('Plugin', APPLICATION_PATH_COR . DS . 'plugins')->register('Widget', APPLICATION_PATH_COR . DS . 'widgets'); // Create application, bootstrap, and run $application = new Engine_Application(APPLICATION_ENV, array('bootstrap' => array('path' => APPLICATION_PATH_COR . DS . 'modules' . DS . APPLICATION_NAME . DS . 'Bootstrap.php', 'class' => ucfirst(APPLICATION_NAME) . '_Bootstrap'))); Engine_Api::getInstance()->setApplication($application); } // config mode if (defined('_ENGINE_R_CONF') && _ENGINE_R_CONF) { return; } if (!empty($_SERVER['_ENGINE_TRACE_ALLOW']) && extension_loaded('xdebug')) { xdebug_start_trace(); } // Sub apps if (_ENGINE_R_MAIN) { require dirname(__FILE__) . DS . _ENGINE_R_MAIN; exit;
protected function _loadFrontend(array $options) { if (!isset($options['adapter']) || !is_string($options['adapter'])) { throw new Engine_Comet_Exception('Adapter not set or not string.'); } $adapter = $options['adapter']; unset($options['adapter']); $class = 'Engine_Comet_Frontend_' . ucfirst($adapter); Engine_Loader::loadClass($class); if (!is_subclass_of($class, 'Engine_Comet_Frontend_Abstract')) { throw new Engine_Comet_Exception(sprintf('Adapter %s does not extend Engine_Comet_Frontend_Abstract', $class)); } return new $class($options); }
/** * Loads a singleton instance of a module resource using a full class name * * @param string $class The class name * @return mixed The requested singleton object */ public function loadClass($class) { return Engine_Loader::getInstance()->load($class); }
protected function _executeTask(Engine_Db_Table_Row $task) { // Return if we reached our limit if ($this->_runCount >= $this->getMaxJobs()) { return $this; } // Log if (APPLICATION_ENV == 'development') { $this->getLog()->log('Task Execution Check: ' . $task->title, Zend_Log::NOTICE); } // Update task using where (this will prevent double executions) $affected = $task->getTable()->update(array('state' => 'active', 'executing' => 1, 'executing_id' => $this->getPid(), 'started_last' => time(), 'started_count' => new Zend_Db_Expr('started_count + 1')), array('task_id = ?' => $task->task_id, 'state = ?' => $task->state, 'executing = ?' => 0, 'executing_id = ?' => 0)); // Refresh $task->refresh(); // If not affected cancel if ($affected !== 1) { // $task->executing_id != $this->getPid() return $this; } // Log if (APPLICATION_ENV == 'development') { $this->getLog()->log('Task Execution Pass: '******'Core_Plugin_Task_Abstract')) { $this->getLog()->log(sprintf('Task plugin %1$s should extend Core_Plugin_Task_Abstract', $task->plugin), Zend_Log::WARN); // Execute plugin $plugin = Engine_Api::_()->loadClass($task->plugin); if (method_exists($plugin, 'execute')) { $plugin->execute(); } else { if (method_exists($plugin, 'executeTask')) { $plugin->executeTask(); } else { throw new Engine_Exception('Task ' . $task->plugin . ' does not have an execute or executeTask method'); } } } else { // Create plugin object $pluginClass = $task->plugin; $plugin = new $pluginClass($task); $plugin->setLog($this->getLog()); // Execute $plugin->execute(); // Ask semi auto ones if they are done yet if ($task->type == 'semi-automatic' && ($plugin instanceof Core_Plugin_Task_PersistentAbstract || method_exists($plugin, 'isComplete'))) { $isComplete = (bool) $plugin->isComplete(); } // Check was idle $wasIdle = $plugin->wasIdle(); } $status = true; } catch (Exception $e) { // Log exception $this->getLog()->log($e->__toString(), Zend_Log::ERR); $status = false; } // Update task if (!$isComplete) { $task->state = 'sleeping'; } else { $task->state = 'dormant'; } $task->executing = false; $task->executing_id = 0; $task->completed_count++; $task->completed_last = time(); if ($status) { $task->success_count++; $task->success_last = time(); } else { $task->failure_count++; $task->failure_last = time(); } $task->save(); // Update count if (!$wasIdle) { $this->_runCount++; } // Remove executing task $this->_executingTask = null; // Log if (APPLICATION_ENV == 'development') { if ($status) { $this->getLog()->log('Task Execution Complete: ' . $task->title, Zend_Log::NOTICE); } else { $this->getLog()->log('Task Execution Complete (with errors): ' . $task->title, Zend_Log::NOTICE); } } return $this; }
/** * Set current loader instance * * @param Engine_Loader $loader */ public static function setInstance(Engine_Loader $loader = null) { self::$_instance = $loader; }
public function indexAction() { // Make filter form $this->view->formFilter = $formFilter = new Core_Form_Admin_Tasks_Filter(); // Process form $values = $this->_getAllParams(); if (null === $this->_getParam('category')) { $values['category'] = 'system'; } if (!$formFilter->isValid($values)) { $values = array(); } else { $values = $formFilter->getValues(); } $values = array_filter($values); $this->view->formFilterValues = $values; // Make select $tasksTable = Engine_Api::_()->getDbtable('tasks', 'core'); $select = $tasksTable->select()->where('module IN(?)', (array) Engine_Api::_()->getDbtable('modules', 'core')->getEnabledModuleNames()); // Make select - order if (empty($values['order'])) { $values['order'] = 'task_id'; } if (empty($values['direction'])) { $values['direction'] = 'ASC'; } $select->order($values['order'] . ' ' . $values['direction']); unset($values['order']); unset($values['direction']); // Make select - where if (isset($values['moduleName'])) { $values['module'] = $values['moduleName']; unset($values['moduleName']); } foreach ($values as $key => $value) { $select->where($tasksTable->getAdapter()->quoteIdentifier($key) . ' = ?', $value); } // Make paginator $this->view->tasks = $tasks = Zend_Paginator::factory($select); $tasks->setItemCountPerPage(25); $tasks->setCurrentPageNumber($this->_getParam('page')); // Get task progresses $taskProgress = array(); foreach ($tasks as $task) { try { Engine_Loader::loadClass($task->plugin); $pluginClass = $task->plugin; $plugin = new $pluginClass($task); if ($plugin instanceof Core_Plugin_Task_Abstract) { $total = $plugin->getTotal(); $progress = $plugin->getProgress(); if ($total || $progress) { $taskProgress[$task->plugin]['progress'] = $plugin->getProgress(); $taskProgress[$task->plugin]['total'] = $plugin->getTotal(); } } } catch (Exception $e) { } } $this->view->taskProgress = $taskProgress; // Get task settings $this->view->taskSettings = Engine_Api::_()->getApi('settings', 'core')->core_tasks; // Get currently executing task info $this->view->currentlyExecutingCount = $tasksTable->select()->from($tasksTable->info('name'), new Zend_Db_Expr('COUNT(*)'))->where('executing = ?', 1)->query()->fetchColumn(0); $this->view->navigation = $this->getNavigation(); }
public function addTest($spec, $options = array()) { if ($spec instanceof Engine_Sanity_Test_Interface) { $test = $spec; } else { if (is_string($spec)) { $class = 'Engine_Sanity_Test_' . ucfirst($spec); Engine_Loader::loadClass($class); $test = new $class($options); } else { if (is_array($spec)) { if (!empty($spec['type'])) { $class = 'Engine_Sanity_Test_' . ucfirst($spec['type']); unset($spec['type']); } else { if (!empty($spec['class'])) { $class = $spec['class']; unset($spec['class']); } else { throw new Engine_Sanity_Exception('No type or class specified for test'); } } Engine_Loader::loadClass($class); $options = array_merge($spec, $options); $test = new $class($options); } } } if (!$test instanceof Engine_Sanity_Test_Interface) { throw new Engine_Sanity_Exception('Test must be an instance of Engine_Sanity_Test_Abstract'); } $this->_tests[] = $test; return $this; }
protected function _initView() { // Create view $view = new Zend_View(); // Set encoding (@todo maybe use configuration?) $view->setEncoding('utf-8'); $view->addScriptPath(APPLICATION_PATH); // Setup and register viewRenderer // @todo we may not need to override zend's $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view); //$viewRenderer = new Engine_Controller_Action_Helper_ViewRenderer($view); $viewRenderer->setViewSuffix('tpl'); Zend_Controller_Action_HelperBroker::getStack()->offsetSet(-80, $viewRenderer); // Initialize contextSwitch helper Zend_Controller_Action_HelperBroker::addHelper(new Core_Controller_Action_Helper_ContextSwitch()); // Add default helper paths $view->addHelperPath('Engine/View/Helper/', 'Engine_View_Helper_'); $this->initViewHelperPath(); // Set doctype Engine_Loader::loadClass('Zend_View_Helper_Doctype'); $doctypeHelper = new Zend_View_Helper_Doctype(); $doctypeHelper->doctype(Engine_Api::_()->getApi('settings', 'core')->getSetting('core.doctype', 'HTML4_LOOSE')); // Add to local container and registry Zend_Registry::set('Zend_View', $view); return $view; }