/** * Returns the manager the controller is using. * * @return MShop_Common_Manager_Interface Manager object */ protected function _getManager() { if ($this->_manager === null) { $this->_manager = MAdmin_Factory::createManager($this->_getContext(), 'job'); } return $this->_manager; }
public function testClearSpecific() { $cache = MAdmin_Factory::setCache(true); $context = TestHelper::getContext(); $managerA1 = MAdmin_Factory::createManager($context, 'log'); $managerB1 = MAdmin_Factory::createManager($context, 'job'); MAdmin_Factory::clear((string) $context, 'log'); $managerA2 = MAdmin_Factory::createManager($context, 'log'); $managerB2 = MAdmin_Factory::createManager($context, 'job'); MAdmin_Factory::setCache($cache); $this->assertNotSame($managerA1, $managerA2); $this->assertSame($managerB1, $managerB2); }
/** * Executes the job. * * @throws Controller_Jobs_Exception If an error occurs */ public function run() { $context = $this->_getContext(); $config = $context->getConfig(); $container = null; /** controller/jobs/admin/log/default/limit-days * Only remove log entries that were created berore the configured number of days * * This option specifies the number of days log entries will be kept in * the database. Afterwards, they will be removed and archived if a * path for storing the archive files is configured. * * @param integer Number of days * @since 2014.09 * @category User * @category Developer * @see controller/jobs/admin/log/default/path * @see controller/jobs/admin/log/default/container/type * @see controller/jobs/admin/log/default/container/format * @see controller/jobs/admin/log/default/container/options */ $limit = $config->get('controller/jobs/admin/log/default/limit-days', 30); $limitDate = date('Y-m-d H:i:s', time() - $limit * 86400); /** controller/jobs/admin/log/default/path * Path to a writable directory where the log archive files should be stored * * During normal operation, a lot of data can be logged, not only for * errors that have occured. By default, these data is written into the * log database and its size will grow if old log entries are not * removed. There's a job controller available that can delete old log * entries. * * If an absolute path to a writeable directory in the file system is * set via this configuration option, the job controller will save the * old log entries to a file in this path. They can be analysed later * if required. * * The type and format of these files as well as the time frame after * the log entries are removed from the log database can be configured * too. * * @param string Absolute file system path to a writable directory * @since 2014.09 * @category Developer * @category User * @see controller/jobs/admin/log/default/container/type * @see controller/jobs/admin/log/default/container/format * @see controller/jobs/admin/log/default/container/options * @see controller/jobs/admin/log/default/limit-days */ if (($path = $config->get('controller/jobs/admin/log/default/path', null)) !== null) { /** controller/jobs/admin/log/default/container/type * Container file type storing all coupon code files to import * * All coupon code files or content objects must be put into one * container file so editors don't have to upload one file for each * coupon code file. * * The container file types that are supported by default are: * * Zip * * Extensions implement other container types like spread sheets, XMLs or * more advanced ways of handling the exported data. * * @param string Container file type * @since 2014.09 * @category Developer * @category User * @see controller/jobs/admin/log/default/path * @see controller/jobs/admin/log/default/container/format * @see controller/jobs/admin/log/default/container/options * @see controller/jobs/admin/log/default/limit-days */ /** controller/jobs/admin/log/default/container/format * Format of the coupon code files to import * * The coupon codes are stored in one or more files or content * objects. The format of that file or content object can be configured * with this option but most formats are bound to a specific container * type. * * The formats that are supported by default are: * * CSV (requires container type "Zip") * * Extensions implement other container types like spread sheets, XMLs or * more advanced ways of handling the exported data. * * @param string Content file type * @since 2014.09 * @category Developer * @category User * @see controller/jobs/admin/log/default/path * @see controller/jobs/admin/log/default/container/type * @see controller/jobs/admin/log/default/container/options * @see controller/jobs/admin/log/default/limit-days */ /** controller/jobs/admin/log/default/container/options * Options changing the expected format of the coupon codes to import * * Each content format may support some configuration options to change * the output for that content type. * * The options for the CSV content format are: * * csv-separator, default ',' * * csv-enclosure, default '"' * * csv-escape, default '"' * * csv-lineend, default '\n' * * For format options provided by other container types implemented by * extensions, please have a look into the extension documentation. * * @param array Associative list of options with the name as key and its value * @since 2014.09 * @category Developer * @category User * @see controller/jobs/admin/log/default/path * @see controller/jobs/admin/log/default/container/type * @see controller/jobs/admin/log/default/container/format * @see controller/jobs/admin/log/default/limit-days */ $type = $config->get('controller/jobs/admin/log/default/container/type', 'Zip'); $format = $config->get('controller/jobs/admin/log/default/container/format', 'CSV'); $options = $config->get('controller/jobs/admin/log/default/container/options', array()); $path .= DIRECTORY_SEPARATOR . str_replace(' ', '_', $limitDate); $container = MW_Container_Factory::getContainer($path, $type, $format, $options); } $manager = MAdmin_Factory::createManager($context, 'log'); $search = $manager->createSearch(); $search->setConditions($search->compare('<=', 'log.timestamp', $limitDate)); $search->setSortations(array($search->sort('+', 'log.timestamp'))); $start = 0; $contents = array(); do { $ids = array(); $items = $manager->searchItems($search); foreach ($items as $id => $item) { if ($container !== null) { $facility = $item->getFacility(); if (!isset($contents[$facility])) { $contents[$facility] = $container->create($facility); } $contents[$facility]->add($item->toArray()); } $ids[] = $id; } $manager->deleteItems($ids); $count = count($items); $start += $count; $search->setSlice($start); } while ($count >= $search->getSliceSize()); if ($container !== null && !empty($contents)) { foreach ($contents as $content) { $container->add($content); } $container->close(); } }
/** * Enables or disables caching of class instances. * * @param boolean $value True to enable caching, false to disable it. * @return boolean Previous cache setting */ public static function setCache($value) { $old = self::$_cache; self::$_cache = (bool) $value; return $old; }
/** * Removes multiple items specified by ids in the array. * * @param array $ids List of IDs */ public function deleteItems(array $ids) { $context = $this->_getContext(); $config = $context->getConfig(); /** mshop/locale/manager/site/default/item/delete * Deletes the items matched by the given IDs from the database * * Removes the site records specified by the given IDs from the * locale database. The records must be from the site that is configured * via the context item. * * The ":cond" placeholder is replaced by the name of the ID column and * the given ID or list of IDs while the site ID is bound to the question * mark. * * The SQL statement should conform to the ANSI standard to be * compatible with most relational database systems. This also * includes using double quotes for table and column names. * * @param string SQL statement for deleting items * @since 2014.03 * @category Developer * @see mshop/locale/manager/site/default/item/insert * @see mshop/locale/manager/site/default/item/update * @see mshop/locale/manager/site/default/item/search * @see mshop/locale/manager/site/default/item/count * @see mshop/locale/manager/site/default/item/newid */ $path = 'mshop/locale/manager/site/default/item/delete'; $this->_deleteItems($ids, $config->get($path, $path), false); /** mshop/locale/manager/site/cleanup/shop/domains * List of madmin domains names whose items referring to the same site should be deleted as well * * As items for each domain can be stored in a separate database, the * site manager needs a list of domain names used to connect to the * correct database and to remove all items that belong the the deleted * site. * * For each domain the cleanup will be done by the corresponding MShop * manager. To keep records for old sites in the database even if the * site was already deleted, you can configure a new list with the * domains removed you would like to keep, e.g. the "order" domain to * keep all orders ever placed. * * @param array List of domain names in lower case * @since 2014.03 * @category Developer * @see mshop/locale/manager/site/cleanup/admin/domains */ $path = 'mshop/locale/manager/site/cleanup/shop/domains'; $default = array('attribute', 'catalog', 'catalog/index', 'coupon', 'customer', 'media', 'order', 'plugin', 'price', 'product', 'product/tag', 'service', 'supplier', 'text'); foreach ($config->get($path, $default) as $domain) { MShop_Factory::createManager($context, $domain)->cleanup($ids); } /** mshop/locale/manager/site/cleanup/admin/domains * List of mshop domains names whose items referring to the same site should be deleted as well * * As items for each domain can be stored in a separate database, the * site manager needs a list of domain names used to connect to the * correct database and to remove all items that belong the the deleted * site. * * For each domain the cleanup will be done by the corresponding MAdmin * manager. To keep records for old sites in the database even if the * site was already deleted, you can configure a new list with the * domains removed you would like to keep, e.g. the "log" domain to * keep all log entries ever written. * * @param array List of domain names in lower case * @since 2014.03 * @category Developer * @see mshop/locale/manager/site/cleanup/shop/domains */ $path = 'mshop/locale/manager/site/cleanup/admin/domains'; $default = array('job', 'log', 'cache'); foreach ($config->get($path, $default) as $domain) { MAdmin_Factory::createManager($context, $domain)->cleanup($ids); } }
/** * Removes multiple items specified by ids in the array. * * @param array $ids List of IDs */ public function deleteItems(array $ids) { $context = $this->_getContext(); $config = $context->getConfig(); $path = 'mshop/locale/manager/site/default/item/delete'; $this->_deleteItems($ids, $config->get($path, $path), false); $path = 'mshop/locale/manager/site/cleanup/shop/domains'; $default = array('attribute', 'catalog', 'catalog/index', 'coupon', 'customer', 'media', 'order', 'plugin', 'price', 'product', 'product/tag', 'service', 'supplier', 'text'); foreach ($config->get($path, $default) as $domain) { MShop_Factory::createManager($context, $domain)->cleanup($ids); } $path = 'mshop/locale/manager/site/cleanup/admin/domains'; $default = array('job', 'log', 'cache'); foreach ($config->get($path, $default) as $domain) { MAdmin_Factory::createManager($context, $domain)->cleanup($ids); } }