コード例 #1
0
ファイル: Standard.php プロジェクト: mvnp/aimeos-core
 /**
  * Executes the job.
  *
  * @throws \Aimeos\Controller\Jobs\Exception If an error occurs
  */
 public function run()
 {
     $context = $this->getContext();
     $jobManager = \Aimeos\MAdmin\Job\Manager\Factory::createManager($context);
     $criteria = $jobManager->createSearch(true);
     $start = 0;
     do {
         $items = $jobManager->searchItems($criteria);
         foreach ($items as $item) {
             try {
                 $job = $item->getMethod();
                 if (preg_match('/^[a-zA-Z0-9\\_]+\\.[a-zA-Z0-9\\_]+$/', $job) !== 1) {
                     throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid characters in job name "%1$s"', $job));
                 }
                 $parts = explode('.', $job);
                 if (count($parts) !== 2) {
                     throw new \Aimeos\Controller\Jobs\Exception(sprintf('Invalid job method "%1$s"', $job));
                 }
                 $method = $parts[1];
                 $class = str_replace('_', '\\', $parts[0]);
                 $name = '\\Aimeos\\Controller\\ExtJS\\' . $class . '\\Factory';
                 if (class_exists($name) === false) {
                     throw new \Aimeos\Controller\Jobs\Exception(sprintf('Class "%1$s" not available', $name));
                 }
                 $name .= '::createController';
                 if (($controller = call_user_func_array($name, array($context))) === false) {
                     throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to call factory method "%1$s"', $name));
                 }
                 if (method_exists($controller, $method) === false) {
                     throw new \Aimeos\Controller\Jobs\Exception(sprintf('Method "%1$s" not available', $method));
                 }
                 $result = $controller->{$method}((object) $item->getParameter());
                 $item->setResult($result);
                 $item->setStatus(-1);
             } catch (\Exception $e) {
                 $str = 'Error while processing job "%1$s": %2$s';
                 $context->getLogger()->log(sprintf($str, $item->getMethod(), $e->getMessage()));
                 $item->setStatus(0);
             }
             $jobManager->saveItem($item);
         }
         $count = count($items);
         $start += $count;
         $criteria->setSlice($start);
     } while ($count > 0);
 }
コード例 #2
0
ファイル: JobAddTestData.php プロジェクト: mvnp/aimeos-core
 /**
  * Adds the job test data.
  *
  * @throws \Aimeos\MW\Setup\Exception If a required ID is not available
  */
 private function addJobTestData()
 {
     $adminJobManager = \Aimeos\MAdmin\Job\Manager\Factory::createManager($this->additional, 'Standard');
     $ds = DIRECTORY_SEPARATOR;
     $path = __DIR__ . $ds . 'data' . $ds . 'job.php';
     if (($testdata = (include $path)) == false) {
         throw new \Aimeos\MShop\Exception(sprintf('No file "%1$s" found for job domain', $path));
     }
     $job = $adminJobManager->createItem();
     $this->conn->begin();
     foreach ($testdata['job'] as $dataset) {
         $job->setId(null);
         $job->setLabel($dataset['label']);
         $job->setMethod($dataset['method']);
         $job->setParameter($dataset['parameter']);
         $job->setResult($dataset['result']);
         $job->setStatus($dataset['status']);
         $adminJobManager->saveItem($job, false);
     }
     $this->conn->commit();
 }
コード例 #3
0
ファイル: FactoryTest.php プロジェクト: mvnp/aimeos-core
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('\\Aimeos\\MShop\\Exception');
     \Aimeos\MAdmin\Job\Manager\Factory::createManager(\TestHelperMShop::getContext(), 'unknown');
 }