public function testRun()
 {
     $config = $this->context->getConfig();
     $mock = $this->getMockBuilder('\\Aimeos\\MAdmin\\Log\\Manager\\Standard')->setMethods(array('deleteItems'))->setConstructorArgs(array($this->context))->getMock();
     $mock->expects($this->atLeastOnce())->method('deleteItems');
     $tmppath = dirname(dirname(dirname(dirname(__DIR__)))) . DIRECTORY_SEPARATOR . 'tmp';
     $name = 'ControllerJobsAdminLogDefaultRun';
     $config->set('madmin/log/manager/name', $name);
     $config->set('controller/jobs/admin/log/standard/limit-days', 0);
     $config->set('controller/jobs/admin/log/standard/path', $tmppath);
     \Aimeos\MAdmin\Log\Manager\Factory::injectManager('\\Aimeos\\MAdmin\\Log\\Manager\\' . $name, $mock);
     if (!is_dir($tmppath) && mkdir($tmppath) === false) {
         throw new \RuntimeException(sprintf('Unable to create temporary path "%1$s"', $tmppath));
     }
     $this->object->run();
     foreach (new \DirectoryIterator($tmppath) as $file) {
         if ($file->isFile() && $file->getExtension() === 'zip') {
             $container = \Aimeos\MW\Container\Factory::getContainer($file->getPathName(), 'Zip', 'CSV', array());
             $container->get('unittest facility.csv');
             unlink($file->getPathName());
             return;
         }
     }
     $this->fail('Log archive file not found');
 }
 protected function setUp()
 {
     $this->context = \TestHelper::getContext('unitperf');
     $config = $this->context->getConfig();
     $config->set('controller/jobs/product/import/csv/location', 'tmp/product-import.zip');
     $config->set('controller/jobs/product/import/csv/container/type', 'Zip');
     $config->set('controller/jobs/product/import/csv/container/content', 'CSV');
     $config->set('controller/jobs/product/import/csv/mapping', $this->getMapping());
     $container = \Aimeos\MW\Container\Factory::getContainer('tmp/product-import.zip', 'Zip', 'CSV', array());
     $content = $container->create('product.csv');
     for ($i = 0; $i < 1000; $i++) {
         $data = array();
         $data = $this->addProduct($data, $i);
         $data = $this->addText($data, $i);
         $data = $this->addMedia($data, $i);
         $data = $this->addPrice($data, $i);
         $data = $this->addAttribute($data, $i);
         $data = $this->addProductRef($data, $i);
         $data = $this->addProperty($data, $i);
         $content->add($data);
     }
     $container->add($content);
     $container->close();
 }
Beispiel #3
0
 /**
  * Opens and returns the container which includes the product data
  *
  * @return \Aimeos\MW\Container\Iface Container object
  */
 protected function getContainer()
 {
     $config = $this->getContext()->getConfig();
     /** controller/jobs/product/import/csv/location
      * File or directory where the content is stored which should be imported
      *
      * You need to configure the file or directory that acts as container
      * for the CSV files that should be imported. It should be an absolute
      * path to be sure but can be relative path if you absolutely know from
      * where the job will be executed from.
      *
      * The path can point to any supported container format as long as the
      * content is in CSV format, e.g.
      * * Directory container / CSV file
      * * Zip container / compressed CSV file
      * * PHPExcel container / PHPExcel sheet
      *
      * @param string Absolute file or directory path
      * @since 2015.05
      * @category Developer
      * @category User
      * @see controller/jobs/product/import/csv/container/type
      * @see controller/jobs/product/import/csv/container/content
      * @see controller/jobs/product/import/csv/container/options
      */
     $location = $config->get('controller/jobs/product/import/csv/location', '.');
     /** controller/jobs/product/import/csv/container/type
      * Nave of the container type to read the data from
      *
      * The container type tells the importer how it should retrieve the data.
      * There are currently three container types that support the necessary
      * CSV content:
      * * Directory
      * * Zip
      * * PHPExcel
      *
      * '''Note:''' For the PHPExcel container, you need to install the
      * "ai-container" extension.
      *
      * @param string Container type name
      * @since 2015.05
      * @category Developer
      * @category User
      * @see controller/jobs/product/import/csv/location
      * @see controller/jobs/product/import/csv/container/content
      * @see controller/jobs/product/import/csv/container/options
      */
     $container = $config->get('controller/jobs/product/import/csv/container/type', 'Directory');
     /** controller/jobs/product/import/csv/container/content
      * Name of the content type inside the container to read the data from
      *
      * The content type must always be a CSV-like format and there are
      * currently two format types that are supported:
      * * CSV
      * * PHPExcel
      *
      * '''Note:''' for the PHPExcel content type, you need to install the
      * "ai-container" extension.
      *
      * @param array Content type name
      * @since 2015.05
      * @category Developer
      * @category User
      * @see controller/jobs/product/import/csv/location
      * @see controller/jobs/product/import/csv/container/type
      * @see controller/jobs/product/import/csv/container/options
      */
     $content = $config->get('controller/jobs/product/import/csv/container/content', 'CSV');
     /** controller/jobs/product/import/csv/container/options
      * List of file container options for the product import files
      *
      * Some container/content type allow you to hand over additional settings
      * for configuration. Please have a look at the article about
      * {@link http://aimeos.org/docs/Developers/Utility/Create_and_read_files container/content files}
      * for more information.
      *
      * @param array Associative list of option name/value pairs
      * @since 2015.05
      * @category Developer
      * @category User
      * @see controller/jobs/product/import/csv/location
      * @see controller/jobs/product/import/csv/container/content
      * @see controller/jobs/product/import/csv/container/type
      */
     $options = $config->get('controller/jobs/product/import/csv/container/options', array());
     return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options);
 }
Beispiel #4
0
 /**
  * Imports a file with coupon codes and optional meta information.
  *
  * @param \stdClass $params Object containing the properties
  */
 public function importFile(\stdClass $params)
 {
     $this->checkParams($params, array('site', 'couponid', 'items'));
     $this->setLocale($params->site);
     /** controller/extjs/coupon/code/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/extjs/coupon/code/standard/container/format
      */
     /** controller/extjs/coupon/code/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/extjs/coupon/code/standard/container/type
      * @see controller/extjs/coupon/code/standard/container/options
      */
     /** controller/extjs/coupon/code/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/extjs/coupon/code/standard/container/format
      */
     $config = $this->getContext()->getConfig();
     $type = $config->get('controller/extjs/coupon/code/standard/container/type', 'Zip');
     $format = $config->get('controller/extjs/coupon/code/standard/container/format', 'CSV');
     $options = $config->get('controller/extjs/coupon/code/standard/container/options', array());
     $items = !is_array($params->items) ? array($params->items) : $params->items;
     foreach ($items as $path) {
         $container = \Aimeos\MW\Container\Factory::getContainer($path, $type, $format, $options);
         foreach ($container as $content) {
             $this->importContent($content, $params->couponid);
         }
         unlink($path);
     }
     return array('success' => true);
 }
Beispiel #5
0
 /**
  * Creates a new container for the site map file
  *
  * @return \Aimeos\MW\Container\Iface Container object
  */
 protected function createContainer()
 {
     $config = $this->getContext()->getConfig();
     /** controller/jobs/product/export/location
      * Directory where the generated site maps should be placed into
      *
      * You have to configure a directory for the generated files on your
      * server that is writeable by the process generating the files, e.g.
      *
      * /var/www/your/export/path
      *
      * @param string Absolute directory to store the exported files into
      * @since 2015.01
      * @category Developer
      * @category User
      * @see controller/jobs/product/export/standard/container/options
      * @see controller/jobs/product/export/max-items
      * @see controller/jobs/product/export/max-query
      */
     $location = $config->get('controller/jobs/product/export/location', sys_get_temp_dir());
     /** controller/jobs/product/export/standard/container/type
      * List of file container options for the export files
      *
      * The generated files are stored using container/content objects from
      * the core.
      *
      * @param string Container name
      * @since 2015.01
      * @category Developer
      * @see controller/jobs/product/export/standard/container/content
      * @see controller/jobs/product/export/standard/container/options
      * @see controller/jobs/product/export/location
      * @see controller/jobs/product/export/max-items
      * @see controller/jobs/product/export/max-query
      */
     $container = $config->get('controller/jobs/product/export/standard/container/type', 'Directory');
     /** controller/jobs/product/export/standard/container/content
      * List of file container options for the export files
      *
      * The generated files are stored using container/content objects from
      * the core.
      *
      * @param array Associative list of option name/value pairs
      * @since 2015.01
      * @category Developer
      * @see controller/jobs/product/export/standard/container/type
      * @see controller/jobs/product/export/standard/container/options
      * @see controller/jobs/product/export/location
      * @see controller/jobs/product/export/max-items
      * @see controller/jobs/product/export/max-query
      */
     $content = $config->get('controller/jobs/product/export/standard/container/content', 'Binary');
     /** controller/jobs/product/export/standard/container/options
      * List of file container options for the export files
      *
      * The generated files are stored using container/content objects from
      * the core.
      *
      * @param array Associative list of option name/value pairs
      * @since 2015.01
      * @category Developer
      * @see controller/jobs/product/export/standard/container/type
      * @see controller/jobs/product/export/standard/container/content
      * @see controller/jobs/product/export/location
      * @see controller/jobs/product/export/max-items
      * @see controller/jobs/product/export/max-query
      */
     $options = $config->get('controller/jobs/product/export/standard/container/options', array());
     return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options);
 }
Beispiel #6
0
 /**
  * Creates a new container for the site map file
  *
  * @return \Aimeos\MW\Container\Iface Container object
  */
 protected function createContainer()
 {
     $config = $this->getContext()->getConfig();
     /** controller/jobs/product/export/sitemap/location
      * Directory where the generated site maps should be placed into
      *
      * The site maps must be publically available for download by the search
      * engines. Therefore, you have to configure a directory for the site
      * maps in your web space that is writeable by the process generating
      * the files, e.g.
      *
      * /var/www/yourshop/your/sitemap/path
      *
      * The location of the site map index file should then be
      * added to the robots.txt in the document root of your domain:
      *
      * Sitemap: https://www.yourshop.com/your/sitemap/path/aimeos-sitemap-index.xml
      *
      * The "sitemapindex-aimeos.xml" file is the site map index file that
      * references the real site map files which contains the links to the
      * products. Please make sure that the protocol and domain
      * (https://www.yourshop.com/) is the same as the ones used in the
      * product links!
      *
      * More details about site maps can be found at
      * {@link http://www.sitemaps.org/protocol.html sitemaps.org}
      *
      * @param string Absolute directory to store the site maps into
      * @since 2015.01
      * @category Developer
      * @category User
      * @see controller/jobs/product/export/sitemap/container/options
      * @see controller/jobs/product/export/sitemap/max-items
      * @see controller/jobs/product/export/sitemap/max-query
      * @see controller/jobs/product/export/sitemap/changefreq
      */
     $location = $config->get('controller/jobs/product/export/sitemap/location', sys_get_temp_dir());
     /** controller/jobs/product/export/sitemap/container/options
      * List of file container options for the site map files
      *
      * The directory and the generated site map files are stored using
      * container/content objects from the core, namely the "Directory"
      * container and the "Binary" content classes. Both implementations
      * support some options:
      * * dir-perm (default: 0755): Permissions if the directory must be created
      * * gzip-level (default: 5): GZip compression level from 0 to 9 (0 = fast, 9 = best)
      *
      * @param array Associative list of option name/value pairs
      * @since 2015.01
      * @category Developer
      * @see controller/jobs/product/export/sitemap/location
      * @see controller/jobs/product/export/sitemap/max-items
      * @see controller/jobs/product/export/sitemap/max-query
      * @see controller/jobs/product/export/sitemap/changefreq
      */
     $options = $config->get('controller/jobs/product/export/sitemap/container/options', array());
     return \Aimeos\MW\Container\Factory::getContainer($location, 'Directory', 'Gzip', $options);
 }
Beispiel #7
0
 /**
  * Creates container for storing export files.
  *
  * @param string $resource Path to the file
  * @param string $key Configuration key prefix for the container type/format/options keys
  * @return \Aimeos\MW\Container\Iface Container item
  */
 protected function createContainer($resource, $key)
 {
     $config = $this->getContext()->getConfig();
     $type = $config->get($key . '/type', 'Zip');
     $format = $config->get($key . '/format', 'CSV');
     $options = $config->get($key . '/options', array());
     return \Aimeos\MW\Container\Factory::getContainer($resource, $type, $format, $options);
 }
Beispiel #8
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();
     }
 }
Beispiel #9
0
 public function testFactoryFail()
 {
     $this->setExpectedException('\\Aimeos\\MW\\Container\\Exception');
     \Aimeos\MW\Container\Factory::getContainer('tempfile', 'notDefined', 'invalid');
 }