Exemple #1
0
 /**
  * Imports posts.
  *
  * @return void
  */
 public function importInfinityBoardPosts()
 {
     $this->info("\tImporting posts ...");
     $query = Board::orderBy('board_uri', 'desc');
     $query = $query->where('board_uri', 'jim');
     $query->chunk(1, function ($boards) {
         foreach ($boards as $board) {
             try {
                 $tTable = $this->tcon->table("posts_{$board->board_uri}");
                 $tCount = $tTable->count();
             } catch (\Illuminate\Database\QueryException $e) {
                 $this->warn("\t\tMissing board /{$board->board_uri}/");
                 continue;
             }
             if ($tCount >= $board->posts_total && $board->board_uri != "cow") {
                 $this->line("\t\tSkipping /{$board->board_uri}/");
                 continue;
             }
             $this->line("\t\tTruncating Infinity Next posts for /{$board->board_uri}/");
             $post_ids = $board->posts()->withTrashed()->lists('post_id');
             FileAttachment::whereIn('post_id', $post_ids)->forceDelete();
             $board->posts()->withTrashed()->forceDelete();
             $board->posts_total = 0;
             $board->save();
             $this->line("\t\tLocking Next posts for /{$board->board_uri}/");
             $this->tcon->unprepared(DB::raw("LOCK TABLES posts_{$board->board_uri} WRITE"));
             @file_get_contents("http://banners.8ch.net/status/{$board->board_uri}/migrating");
             $this->line("\t\tImporting posts from /{$board->board_uri}/");
             // Post Info
             $postsMade = 0;
             $validThreads = [];
             // Attachment Info
             $storageLinked = 0;
             $attachmentsMade = 0;
             // Threads first, replies by id.
             $query = $tTable->orderByRaw('thread asc, id asc');
             $bar = $this->output->createProgressBar($tCount);
             $query->chunk(50, function ($posts) use(&$bar, &$validThreads, &$board, &$postsMade, &$attachmentsMade) {
                 $models = [];
                 // thread, subject, email, name, trip, capcode, body, body_nomarkup, time, bump, files, num_files, filehash, password, ip, sticky, locked, cycle, sage, embed, edited_at
                 // post_id | board_uri | board_id | reply_to | reply_to_board_id | reply_count | reply_last | bumped_last | created_at | updated_at | updated_by | deleted_at | stickied | stickied_at | bumplocked_at | locked_at | author_ip | author_id | author_country | author_ip_nulled_at | author | insecure_tripcode | capcode_id | adventure_id | subject | email | password | body | body_parsed | body_parsed_at | body_html | featured_at | body_too_long | body_parsed_preview | flag_id | reply_file_count
                 foreach ($posts as $post) {
                     $model = $this->importInfinityPost($post, $board, $validThreads);
                     if (!is_array($model)) {
                         continue;
                     }
                     $model = new Post($model);
                     $model->save();
                     ++$postsMade;
                     // Have to save threads so we have a post_id.
                     if (!$post->thread) {
                         $validThreads[$post->id] = $model;
                     }
                     $attachmentsMade += $this->importInfinityPostAttachments($model, $board, $post);
                 }
                 $bar->advance(count($posts));
                 foreach ($validThreads as $validThread) {
                     $validThread->reply_count = $validThread->replies()->count();
                     $validThread->save();
                 }
             });
             $this->tcon->unprepared(DB::raw("UNLOCK TABLES"));
             @file_get_contents("https://banners.8ch.net/status/{$board->board_uri}/horizon");
             $this->line("\n\t\t\tMade {$postsMade} posts with {$attachmentsMade} attachments for /{$board->board_uri}/.");
         }
     });
 }