/**
  * remove update product lifespan task from scheduler
  *
  * @param Zend_Scheduler $_scheduler
  */
 public static function removeUpdateProductLifespanTask(Zend_Scheduler $_scheduler)
 {
     $_scheduler->removeTask('Sales_Controller_Product::updateProductLifespan');
     $_scheduler->saveTask();
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Removed task Sales_Controller_Product::updateProductLifespan from scheduler.');
     }
 }
 /**
  * add update constraints exdates task to scheduler
  * 
  * @param Zend_Scheduler $_scheduler
  */
 public static function addUpdateConstraintsExdatesTask(Zend_Scheduler $_scheduler)
 {
     $task = self::getPreparedTask(self::TASK_TYPE_DAILY, array('controller' => 'Calendar_Controller_Event', 'action' => 'updateConstraintsExdates'));
     $_scheduler->addTask('Calendar_Controller_Event::updateConstraintsExdates', $task);
     $_scheduler->saveTask();
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Saved task Calendar_Controller_Event::updateConstraintsExdates in scheduler.');
     }
 }
 /**
  * add update product lifespan task to scheduler
  * 
  * @param Zend_Scheduler $_scheduler
  */
 public static function addUpdateProductLifespanTask(Zend_Scheduler $_scheduler)
 {
     $task = self::getPreparedTask(self::TASK_TYPE_HOURLY, array('controller' => 'Sales_Controller_Product', 'action' => 'updateProductLifespan'));
     $_scheduler->addTask('Sales_Controller_Product::updateProductLifespan', $task);
     $_scheduler->saveTask();
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Saved task Sales_Controller_Product::updateProductLifespan in scheduler.');
     }
 }
 /**
  * Singleton instance
  *
  * @return Zend_Scheduler
  */
 public static function getScheduler()
 {
     if (!self::get(self::SCHEDULER) instanceof Zend_Scheduler) {
         $scheduler = new Zend_Scheduler();
         $scheduler->setBackend(new Zend_Scheduler_Backend_Db(array('DbAdapter' => self::getDb(), 'tableName' => SQL_TABLE_PREFIX . 'scheduler', 'taskClass' => 'Tinebase_Scheduler_Task')));
         self::set(self::SCHEDULER, $scheduler);
     }
     return self::get(self::SCHEDULER);
 }
 /**
  * can run task
  */
 public function testCanRunTask()
 {
     $this->testSaveTask();
     $result = $this->_scheduler->run();
     $this->assertGreaterThan(0, count($result));
 }
 /**
  * Tests any given backend.
  *
  * @param Zend_Scheduler $scheduler
  * @param Zend_Scheduler_Backend_Abstract $backend
  */
 protected function _canUseBackend(Zend_Scheduler_Backend_Abstract $backend)
 {
     $controller = Zend_Controller_Front_Mock::getInstance();
     $controller->returnResponse(true);
     $controller->throwExceptions(true);
     $scheduler = new Zend_Scheduler($backend);
     $scheduler->setController($controller);
     $scheduler->setLimit(1);
     // Only execute one task
     $task = new Zend_Scheduler_Task();
     $task->addRequest('scheduled', 'task1');
     $task->addRequest('scheduled', 'task2');
     $scheduler->addTask('test1', $task);
     $task = new Zend_Scheduler_Task();
     $task->setRequest('scheduled', 'task3');
     $scheduler->addTask('test2', $task);
     $task = new Zend_Scheduler_Task();
     $task->setRequest('scheduled', 'task4');
     $scheduler->addTask('test3', $task);
     try {
         $scheduler->run();
     } catch (Zend_Scheduler_Exception $e) {
         $this->fail('Could not execute tasks: ' . $e->getMessage());
     }
     try {
         $tasks = $backend->loadQueue();
     } catch (Zend_Scheduler_Exception $e) {
         $this->fail('Could not load task queue');
     }
     $taskCount = count($tasks);
     $this->assertEquals(2, $taskCount, "Expected 2 tasks in queue, received {$taskCount}");
     $tasksFound = isset($tasks['test2']) and isset($tasks['test3']);
     $this->assertTrue($tasksFound, 'Did not find expected tasks in queue');
     $this->assertType('Zend_Scheduler_Task', $tasks['test2'], 'Received task did not match type');
 }
 /**
  * Tests if a valid (i.e., included) backend can be loaded.
  */
 public function testCanLoadValidBackend()
 {
     $scheduler = new Zend_Scheduler();
     try {
         $scheduler->setBackend('File');
     } catch (Exception $e) {
         $this->fail('Denied the use of a valid backend');
     }
 }
 /**
  * add access log cleanup task to scheduler
  * 
  * @param Zend_Scheduler $_scheduler
  */
 public static function addAccessLogCleanupTask(Zend_Scheduler $_scheduler)
 {
     $task = Tinebase_Scheduler_Task::getPreparedTask(Tinebase_Scheduler_Task::TASK_TYPE_DAILY, array('controller' => 'Tinebase_AccessLog', 'action' => 'clearTable'));
     $_scheduler->addTask('Tinebase_AccessLogCleanup', $task);
     $_scheduler->saveTask();
     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Saved task Tinebase_AccessLog::clearTable in scheduler.');
     }
 }