/**
  * @param RequestInterface  $request  A PSR-7 compatible Request instance.
  * @param ResponseInterface $response A PSR-7 compatible Response instance.
  * @return ResponseInterface
  */
 public function run(RequestInterface $request, ResponseInterface $response)
 {
     unset($request);
     $this->startLock();
     $climate = $this->climate();
     $loader = new CollectionLoader(['logger' => $this->logger, 'factory' => $this->scheduleFactory()]);
     $loader->setModel($this->scheduleProto());
     $loader->addFilter(['property' => 'processed', 'val' => 0]);
     $loader->addFilter(['property' => 'scheduled_date', 'val' => date('Y-m-d H:i:s'), 'operator' => '<']);
     $loader->addOrder(['property' => 'scheduled_date', 'mode' => 'asc']);
     $scheduled = $loader->load();
     $callback = function ($obj) use($climate) {
         // No default callback
     };
     $successCallback = function ($obj) use($climate) {
         $climate->green()->out(sprintf('Object %s : %s schedule was successfully ran.', $obj->targetType(), $obj->targetId()));
     };
     $failureCallback = function ($obj) use($climate) {
         $climate->red()->out(sprintf('Object %s : %s schedule could not be ran.', $obj->targetType(), $obj->targetId()));
     };
     foreach ($scheduled as $schedule) {
         $schedule->setModelFactory($this->modelFactory());
         $schedule->process($callback, $successCallback, $failureCallback);
     }
     $this->stopLock();
     return $response;
 }
 /**
  * Retrieves all revisions for the current objet
  *
  * @param callable $callback Optional object callback.
  * @return array
  */
 public function allRevisions(callable $callback = null)
 {
     $loader = new CollectionLoader(['logger' => $this->logger, 'factory' => $this->modelFactory()]);
     $loader->setModel($this->createRevisionObject());
     $loader->addFilter('target_type', $this->objType());
     $loader->addFilter('target_id', $this->id());
     $loader->addOrder('rev_ts', 'desc');
     if ($callback !== null) {
         $loader->setCallback($callback);
     }
     $revisions = $loader->load();
     return $revisions->objects();
 }
 /**
  * Retrieve the items of the current queue.
  *
  * @return Collection
  */
 public function loadQueueItems()
 {
     $loader = new CollectionLoader(['logger' => $this->logger, 'factory' => $this->queueItemFactory()]);
     $loader->setModel($this->queueItemProto());
     $loader->addFilter(['property' => 'processed', 'val' => 0]);
     $loader->addFilter(['property' => 'processing_date', 'val' => date('Y-m-d H:i:s'), 'operator' => '<']);
     $queueId = $this->queueId();
     if ($queueId) {
         $loader->addFilter(['property' => 'queue_id', 'val' => $queueId]);
     }
     $loader->addOrder(['property' => 'queued_date', 'mode' => 'asc']);
     $queued = $loader->load();
     return $queued;
 }
 /**
  * HierarchicalTrait > loadChildren
  *
  * @return Co
  */
 public function loadChildren()
 {
     $loader = new CollectionLoader(['logger' => $this->logger, 'factory' => $this->modelFactory()]);
     $loader->setModel($this);
     $loader->addFilter(['property' => 'master', 'val' => $this->id()]);
     $loader->addFilter(['property' => 'active', 'val' => true]);
     $loader->addOrder(['property' => 'position', 'mode' => 'asc']);
     return $loader->load();
 }