예제 #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $carbonNow = Carbon::now();
     // Load all of our boards with their settings and threads, 100 at a time.
     Board::with(['settings', 'threads' => function ($query) {
         // OPs
         $query->whereNull('reply_to');
         // Not stickied
         $query->whereNull('stickied_at');
         // Oldest first
         $query->orderBy('bumped_last', 'desc');
     }])->chunk(100, function ($boards) use($carbonNow) {
         $this->comment("    Pruning 100 boards...");
         // With each board, fetch their autoprune settings.
         foreach ($boards as $board) {
             //$this->handleThreadEphemeral($board, $carbonNow);
         }
     });
     $this->handlePostInformation();
     // Run this second so pruned posts from the above are included.
     $this->handleMediaFiles();
 }
예제 #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $carbonNow = Carbon::now();
     // Load all of our boards with their settings and threads, 100 at a time.
     Board::with(['settings', 'threads' => function ($query) {
         // Avoid selecting the content of a thread.
         $query->select('post_id', 'reply_to', 'board_id', 'reply_to_board_id', 'reply_last', 'bumped_last', 'created_at', 'updated_at', 'deleted_at', 'stickied_at', 'bumplocked_at', 'locked_at', 'body_parsed_at', 'author_ip', 'author_ip_nulled_at');
         // OPs
         $query->whereNull('reply_to');
         // Not stickied
         $query->whereNull('stickied_at');
         // Oldest first
         $query->orderBy('bumped_last', 'desc');
     }])->chunk(25, function ($boards) use($carbonNow) {
         $this->comment("    Pruning 25 boards...");
         // With each board, fetch their autoprune settings.
         foreach ($boards as $board) {
             $this->handleThreadEphemeral($board, $carbonNow);
         }
     });
     $this->handlePostInformation();
     // Run this second so pruned posts from the above are included.
     $this->handleMediaFiles();
 }
예제 #3
0
 /**
  * Returns the current stylesheet's raw CSS.
  *
  * @return string
  */
 public function getStylesheet()
 {
     return Cache::remember("board.{$this->board_uri}.stylesheet", 30, function () {
         $stealFrom = $this->getConfig('boardCustomCSSSteal', "");
         if ($stealFrom != "") {
             $stealFrom = Board::with('settings', 'settings.option')->where('board_uri', $stealFrom)->first();
             if ($stealFrom && $stealFrom->exists) {
                 $stealFromStyle = $stealFrom->getConfig('boardCustomCSSEnable', false) ? $stealFrom->getConfig('boardCustomCSS') : "";
                 if ($stealFromStyle != "") {
                     return "/**\n * This style is borrowed from /{$stealFrom->board_uri}/.\n */\n\n\n" . $stealFromStyle;
                 }
             }
         }
         $style = $this->getConfig('boardCustomCSS', "");
         if ($style == "" && !$this->isWorksafe()) {
             $style = file_get_contents(public_path() . "/static/css/skins/next-yotsuba.css");
         }
         return $style;
     });
 }
예제 #4
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $carbonNow = Carbon::now();
     // Load all of our boards with their settings and threads, 100 at a time.
     Board::with(['settings', 'threads' => function ($query) {
         $query->whereNull('reply_to');
         $query->whereNull('stickied_at');
         $query->orderBy('bumped_last', 'desc');
     }])->chunk(100, function ($boards) use($carbonNow) {
         $this->comment("    Pruning 100 boards...");
         // With each board, fetch their autoprune settings.
         foreach ($boards as $board) {
             // Get important settings.
             $threadsPerPage = (int) $board->getSetting('postsPerPage', 10);
             // Collect a list of threads which have been modified.
             $threadsToSave = [];
             // There are two groups of autoprune settings.
             // x on day since last reply
             $sageOnDay = (int) $board->getSetting('epheSageThreadDays');
             $lockOnDay = (int) $board->getSetting('epheLockThreadDays');
             $deleteOnDay = (int) $board->getSetting('epheDeleteThreadDays');
             // x on page (meaning the thread has fallen to this page)
             $sageOnPage = (int) $board->getSetting('epheSageThreadPage');
             $lockOnPage = (int) $board->getSetting('epheLockThreadPage');
             $deleteOnPage = (int) $board->getSetting('epheDeleteThreadPage');
             // Don't do anything unless we have to.
             if ($sageOnDay || $lockOnDay || $deleteOnDay || $sageOnPage || $lockOnPage || $deleteOnPage) {
                 $this->comment("       Pruning /{$board->board_uri}/...");
                 // Modify threads based on these settings.
                 foreach ($board->threads as $threadIndex => $thread) {
                     $threadPage = (int) (floor($threadIndex / $threadsPerPage) + 1);
                     $modified = false;
                     $replyLast = clone $thread->reply_last;
                     // x on day since last reply
                     // This is asking if:
                     // 1) The setting is set ($x > 0)
                     // 2) the last reply date + the number of days permitted by each setting is < now.
                     if (!$thread->isBumplocked() && ($sageOnDay > 0 && $replyLast->addDays($sageOnDay)->isPast() || $sageOnPage > 0 && $sageOnPage <= $threadPage)) {
                         $this->comment("           Bumplocking #{$thread->board_id}");
                         $modified = true;
                         $thread->bumplocked_at = $carbonNow;
                     }
                     if (!$thread->isLocked() && ($lockOnDay > 0 && $replyLast->addDays($lockOnDay)->isPast() || $lockOnPage > 0 && $lockOnPage <= $threadPage)) {
                         $this->comment("           Locking #{$thread->board_id}");
                         $modified = true;
                         $thread->locked_at = $carbonNow;
                     }
                     if (!$thread->isDeleted() && ($deleteOnDay > 0 && $replyLast->addDays($sageOnDay)->isPast() || $deleteOnPage > 0 && $deleteOnPage <= $threadPage)) {
                         $this->comment("           Deleting #{$thread->board_id}");
                         $modified = true;
                         $thread->deleted_at = $carbonNow;
                     }
                     if ($modified) {
                         $threadsToSave[] = $thread;
                     }
                 }
                 if (count($threadsToSave)) {
                     // Save all at once.
                     $board->threads()->saveMany($threadsToSave);
                 } else {
                     $this->comment("           Nothing to do.");
                 }
             }
         }
     });
 }
예제 #5
0
 public function run()
 {
     $this->command->info('Seeding role to user associations.');
     $userRoles = [];
     $admins = User::whereIn('user_id', explode(",", env('APP_ROOT_USERS', "1")))->get();
     foreach ($admins as $admin) {
         $userRoles[] = ['user_id' => $admin->user_id, 'role_id' => Role::ID_ADMIN];
     }
     Board::with('operator', 'roles')->has('operator')->chunk(50, function ($boards) use(&$userRoles) {
         foreach ($boards as $board) {
             $boardRole = $board->getOwnerRole();
             // Drops all board owner user roles where the user isn't a board operator.
             $removed = UserRole::whereHas('role', function ($query) use($boardRole) {
                 $query->where('role_id', $boardRole->role_id);
             })->whereHas('user', function ($query) use($board) {
                 $query->where('user_id', "<>", $board->operated_by);
             })->forceDelete();
             if ($removed > 0) {
                 $this->command->line("\tRemoved {$removed} pretenders from /{$board->board_uri}/.");
             }
             $userRoles[] = ['user_id' => $board->operated_by, 'role_id' => $boardRole->role_id];
         }
     });
     foreach ($userRoles as $userRole) {
         UserRole::firstOrCreate($userRole);
     }
 }