Exemple #1
0
 /**
  * Imports board attachments.
  *
  * @return void
  */
 public function importInfinityAttachments()
 {
     $this->info("\tImporting attachments ...");
     Board::where('board_uri', '>=', "jonimu")->orderBy('board_uri', 'asc')->chunk(1, function ($boards) {
         foreach ($boards as $board) {
             FileAttachment::whereForBoard($board)->forceDelete();
             $this->line("\t\tImporting attachments from /{$board->board_uri}/");
             $tTable = $this->tcon->table("posts_{$board->board_uri}");
             $storageLinked = 0;
             $attachmentsMade = 0;
             // Threads first, replies by id.
             $tTable->where('num_files', '>', 0)->orderByRaw('thread asc, id asc')->chunk(200, function ($posts) use(&$board, &$attachmentsMade, &$storageLinked) {
                 $this->line("\t\t\tImporting 200 more posts's attachments ...");
                 $aModels = [];
                 $fModels = [];
                 $skips = 0;
                 // [{
                 // 	"name":"1417727856564.png",
                 // 	"type":"image\/png",
                 // 	"tmp_name":"\/tmp\/php05oN25",
                 // 	"error":0,
                 // 	"size":13034,
                 // 	"filename":"1417727856564.png",
                 // 	"extension":"png",
                 // 	"file_id":"1423141860833",
                 // 	"file":"1423141860833.png",
                 // 	"thumb":"1423141860833.jpg",
                 // 	"is_an_image":true,
                 // 	"hash":"8c63f0b812657c38966ddc7d387a9a4b",
                 // 	"width":223,
                 // 	"height":200,
                 // 	"thumbwidth":223,
                 // 	"thumbheight":200,
                 // 	"file_path":"b\/src\/1423141860833.png",
                 // 	"thumb_path":"b\/thumb\/1423141860833.jpg"
                 // }]
                 // files, num_files, filehash
                 foreach ($posts as $post) {
                 }
                 if (FileAttachment::insert($aModels)) {
                     $attachmentsMade += count($aModels);
                 }
             });
             $this->line("\t\t\tImported {$storageLinked} files with {$attachmentsMade} attachments.");
         }
     });
 }