ScriptController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: NODELOG
  5. * Date: 2016/12/8
  6. * Time: 下午10:46
  7. */
  8. namespace console\controllers;
  9. use common\models\Article;
  10. use common\models\ArticleTag;
  11. use common\models\Attachment;
  12. use common\models\Comment;
  13. use common\models\Tag;
  14. use yii\base\Exception;
  15. use yii\console\Controller;
  16. class ScriptController extends Controller
  17. {
  18. public function actionConfirmComment()
  19. {
  20. $query = Article::find();
  21. foreach ($query->each() as $item) {
  22. $comment = Comment::find()->where(['type' => 'article', 'type_id' => $item->id])->count();
  23. $item->comment = $comment;
  24. $item->save(false);
  25. }
  26. }
  27. public function actionDeleteAttachment()
  28. {
  29. foreach(Attachment::find()->each() as $model) {
  30. try {
  31. $file = file_get_contents($model->url);
  32. if (!$file) {
  33. throw new Exception('文件内容未空');
  34. }
  35. } catch (\Exception $e) {
  36. $model->delete();
  37. }
  38. }
  39. }
  40. public function actionConfirmTag()
  41. {
  42. foreach (Tag::find()->each() as $model) {
  43. $count = ArticleTag::find()->where(['tag_id' => $model->id])->count();
  44. $model->article = $count;
  45. $model->save(false);
  46. }
  47. }
  48. }