示例#1
0
 /**
  * @dataProvider methodProvider
  */
 public function testRunInvalidMethod($method)
 {
     $context = TestHelper::getContext();
     $arcavias = TestHelper::getArcavias();
     $name = 'ControllerJobsAdminJobDefaultRun';
     $context->getConfig()->set('classes/job/manager/name', $name);
     $object = new Controller_Jobs_Admin_Job_Default($context, $arcavias);
     MAdmin_Job_Manager_Factory::injectManager('MAdmin_Job_Manager_' . $name, $this->_jobManagerStub);
     $this->_jobManagerStub->expects($this->atLeastOnce())->method('searchItems')->will($this->onConsecutiveCalls(array($this->_jobItemStub), array()));
     $this->_jobManagerStub->expects($this->once())->method('saveItem');
     $this->_jobItemStub->expects($this->atLeastOnce())->method('getMethod')->will($this->returnValue($method));
     $this->_jobItemStub->expects($this->once())->method('setStatus')->with($this->equalTo(0));
     $object->run();
 }
示例#2
0
 /**
  * Executes the job.
  *
  * @throws Controller_Jobs_Exception If an error occurs
  */
 public function run()
 {
     $context = $this->_getContext();
     $jobManager = 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 Controller_Jobs_Exception(sprintf('Invalid characters in job name "%1$s"', $job));
                 }
                 $parts = explode('.', $job);
                 if (count($parts) !== 2) {
                     throw new Controller_Jobs_Exception(sprintf('Invalid job method "%1$s"', $job));
                 }
                 $name = "Controller_ExtJS_{$parts[0]}_Factory";
                 $method = $parts[1];
                 if (class_exists($name) === false) {
                     throw new Controller_Jobs_Exception(sprintf('Class "%1$s" not available', $name));
                 }
                 $name .= '::createController';
                 if (($controller = call_user_func_array($name, array($context))) === false) {
                     throw new Controller_Jobs_Exception(sprintf('Unable to call factory method "%1$s"', $name));
                 }
                 if (method_exists($controller, $method) === false) {
                     throw new 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);
 }
示例#3
0
 /**
  * Adds the job test data.
  *
  * @throws MW_Setup_Exception If a required ID is not available
  */
 private function _addJobTestData()
 {
     $adminJobManager = MAdmin_Job_Manager_Factory::createManager($this->_additional, 'Default');
     $ds = DIRECTORY_SEPARATOR;
     $path = dirname(__FILE__) . $ds . 'data' . $ds . 'job.php';
     if (($testdata = (include $path)) == false) {
         throw new 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();
 }
示例#4
0
 public function testCreateManagerNotExisting()
 {
     $this->setExpectedException('MShop_Exception');
     MAdmin_Job_Manager_Factory::createManager(TestHelper::getContext(), 'notexist');
 }
示例#5
0
 /**
  * Initializes the job controller.
  *
  * @param MShop_Context_Item_Interface $context MShop context object
  */
 public function __construct(MShop_Context_Item_Interface $context)
 {
     parent::__construct($context, 'Admin_Job');
     $this->_manager = MAdmin_Job_Manager_Factory::createManager($context);
 }