Exemple #1
0
 public function actionUpdate()
 {
     //$param = $request->getBodyParam('id');
     $id = \Yii::$app->getRequest()->post('id');
     $status = \Yii::$app->getRequest()->post('status');
     if (empty($id) || empty($status)) {
         $error = new Error(Error::CODE_PARAMETER_ERROR);
         return $this->renderContent(json_encode($error->toArray()));
     }
     $model = Plugin::findOne(['id' => $id]);
     if ($model === null) {
         $error = new Error(Error::CODE_OBJECT_NOT_FOUND);
         return $this->renderContent(json_encode($error->toArray()));
     }
     $model->plugin_status = $status;
     if (!$model->save()) {
         $error = new Error(Error::CODE_UPDATE_FAILED);
         return $this->renderContent(json_encode($error->toArray()));
     }
     $success = new Success();
     return $this->renderContent(json_encode($success->toArray()));
 }
 public function actionUpdate()
 {
     $httpRequest = $this->context->getService('httpRequest');
     if ($this->option->get('cron') != $httpRequest->getQuery('cron')) {
         throw new \Nette\Application\BadRequestException("Invalid request");
     }
     $feeds = $this->feed->get_all();
     foreach ($feeds as $feed) {
         try {
             $articles = $this->feed->parse_articles($feed->id);
             $this->article->add_multiple($articles);
             // Debugger::dump($articles);
             // exit;
         } catch (\Exception $e) {
             $this->error->save($feed->id, $e);
         }
         libxml_clear_errors();
     }
     $this->terminate();
 }