Ejemplo n.º 1
0
 /**
  * Returns the manager the controller is using.
  *
  * @return \Aimeos\MShop\Common\Manager\Iface Manager object
  */
 protected function getManager()
 {
     if ($this->manager === null) {
         $this->manager = \Aimeos\MAdmin\Factory::createManager($this->getContext(), 'job');
     }
     return $this->manager;
 }
Ejemplo n.º 2
0
 public function testClearSpecific()
 {
     $cache = \Aimeos\MAdmin\Factory::setCache(true);
     $context = \TestHelper::getContext();
     $managerA1 = \Aimeos\MAdmin\Factory::createManager($context, 'log');
     $managerB1 = \Aimeos\MAdmin\Factory::createManager($context, 'job');
     \Aimeos\MAdmin\Factory::clear((string) $context, 'log');
     $managerA2 = \Aimeos\MAdmin\Factory::createManager($context, 'log');
     $managerB2 = \Aimeos\MAdmin\Factory::createManager($context, 'job');
     \Aimeos\MAdmin\Factory::setCache($cache);
     $this->assertNotSame($managerA1, $managerA2);
     $this->assertSame($managerB1, $managerB2);
 }
Ejemplo n.º 3
0
 /**
  * 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/standard/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/standard/insert
      * @see mshop/locale/manager/site/standard/update
      * @see mshop/locale/manager/site/standard/search
      * @see mshop/locale/manager/site/standard/count
      * @see mshop/locale/manager/site/standard/newid
      */
     $path = 'mshop/locale/manager/site/standard/delete';
     $this->deleteItemsBase($ids, $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', 'coupon', 'customer', 'index', 'media', 'order', 'plugin', 'price', 'product', 'product/tag', 'service', 'supplier', 'text');
     foreach ($config->get($path, $default) as $domain) {
         \Aimeos\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) {
         \Aimeos\MAdmin\Factory::createManager($context, $domain)->cleanup($ids);
     }
 }
Ejemplo n.º 4
0
 /**
  * Executes the job.
  *
  * @throws \Aimeos\Controller\Jobs\Exception If an error occurs
  */
 public function run()
 {
     $context = $this->getContext();
     $config = $context->getConfig();
     $container = null;
     /** controller/jobs/admin/log/standard/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/standard/path
      * @see controller/jobs/admin/log/standard/container/type
      * @see controller/jobs/admin/log/standard/container/format
      * @see controller/jobs/admin/log/standard/container/options
      */
     $limit = $config->get('controller/jobs/admin/log/standard/limit-days', 30);
     $limitDate = date('Y-m-d H:i:s', time() - $limit * 86400);
     /** controller/jobs/admin/log/standard/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/standard/container/type
      * @see controller/jobs/admin/log/standard/container/format
      * @see controller/jobs/admin/log/standard/container/options
      * @see controller/jobs/admin/log/standard/limit-days
      */
     if (($path = $config->get('controller/jobs/admin/log/standard/path', null)) !== null) {
         /** controller/jobs/admin/log/standard/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/standard/path
          * @see controller/jobs/admin/log/standard/container/format
          * @see controller/jobs/admin/log/standard/container/options
          * @see controller/jobs/admin/log/standard/limit-days
          */
         /** controller/jobs/admin/log/standard/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/standard/path
          * @see controller/jobs/admin/log/standard/container/type
          * @see controller/jobs/admin/log/standard/container/options
          * @see controller/jobs/admin/log/standard/limit-days
          */
         /** controller/jobs/admin/log/standard/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/standard/path
          * @see controller/jobs/admin/log/standard/container/type
          * @see controller/jobs/admin/log/standard/container/format
          * @see controller/jobs/admin/log/standard/limit-days
          */
         $type = $config->get('controller/jobs/admin/log/standard/container/type', 'Zip');
         $format = $config->get('controller/jobs/admin/log/standard/container/format', 'CSV');
         $options = $config->get('controller/jobs/admin/log/standard/container/options', array());
         $path .= DIRECTORY_SEPARATOR . str_replace(' ', '_', $limitDate);
         $container = \Aimeos\MW\Container\Factory::getContainer($path, $type, $format, $options);
     }
     $manager = \Aimeos\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();
     }
 }