Пример #1
0
 /**
  * Imports board tags.
  *
  * @return void
  */
 public function importInfinityBoardTags()
 {
     # THEIR TABLES
     $tTagsTable = $this->tcon->table("board_tags");
     # BEGIN USER IMPORT
     $this->info("\tImporting Tags ...");
     $tTagsTable->chunk(100, function ($tags) {
         $this->line("\t\tImporting 100 tags.");
         $boardTags = [];
         $tagModels = [];
         foreach ($tags as $tag) {
             $tagTxt = substr((string) $tag->tag, 0, 32);
             if (!isset($boardTags[$tag->uri])) {
                 $boardTags[$tag->uri] = [];
             }
             if (!isset($tagModels[$tagTxt])) {
                 $tagModels[$tagTxt] = BoardTag::firstOrCreate(['tag' => $tagTxt]);
             }
             $boardTags[$tag->uri] = $tagModels[$tagTxt];
         }
         foreach ($boardTags as $board_uri => $tags) {
             $board = Board::find($board_uri);
             if ($board) {
                 $board->tags()->attach($tags);
             } else {
                 $this->warn("\t\t\tBoard \"{$board_uri}\" could not be found to add tags to.");
             }
         }
         unset($tag, $tagModel, $tagModels, $boardTags);
     });
 }