示例#1
0
 public function init()
 {
     parent::init();
     if (!$this->_baseFinder instanceof BaseFinderInterface) {
         throw new \yii\base\InvalidConfigException('DeferredTask::$_baseFinder must be an instance of BaseFinderInterface.');
     }
     if (!$this->_userFinder instanceof UserFinderInterface) {
         throw new \yii\base\InvalidConfigException('DeferredTask::$_userFinder must be an instance of UserFinderInterface.');
     }
 }
示例#2
0
 public function init()
 {
     parent::init();
     $this->_dirtyModels = new \SplObjectStorage();
     $this->_dirtyModelsInfo = [];
     // whenever a base is loaded, update its stock
     //    Event::on( Base::className(), Base::EVENT_AFTER_FIND,
     //      function ($event) {
     //        $this->updateStock( $event->sender );
     //      }
     //    );
     // whenever a user is loaded, execute the user's finished tasks
     //    Event::on( User::className(), User::EVENT_AFTER_FIND,
     //      function ($event) {
     //        $this->executeFinishedTasks( $event->sender );
     //      }
     //    );
     Event::on(AbstractTask::className(), AbstractTask::EVENT_MODEL_MODIFIED, function (ModelModifiedEvent $event) {
         $this->addDirtyModel($event->model);
     });
     Event::on(ConstructBuildingTask::className(), ConstructBuildingTask::EVENT_BEFORE_BUILDING_CONSTRUCTED, function (ConstructBuildingTaskEvent $event) {
         $this->updateStock($event->base, $event->time);
     });
 }