table('posts')->where('type', 'bericht')->delete(); Storage::disk('upload')->deleteDirectory('uploads/meldung'); } $articles = DB::connection('mysql_alt')->select("SELECT * FROM ikarus_meldung ORDER BY 'id'"); foreach($articles as $article) { // Fallunterscheidung: // Das Element wird nuer importiert, wenn // A) $mode == 'replace' // oder // B) $mode != 'replace' und die ID aus der Altdatenbank ist noch nicht importiert worden $checkMigration = PostMigration::where('type', 'artikel')->where('old_id', $article->id)->get(); if(($mode == 'replace') || ($mode == 'update' && $checkMigration->count() == 0)) { $new_user = User::find($article->benutzer_id); if(!$new_user) { $article->benutzer_id = 1; $new_user = User::find($article->benutzer_id); } \Auth::login($new_user); echo "INSERT article: $article->id\n"; $post = new Post; $post->type = 'bericht'; $post->title = $article->titel; $post->datetime = $article->created_at; // $post->datetime = Carbon::parse($post->datetime)->addYears(2); $post->content = MigrationHelper::normalize($article->beschreibung); $post->user_id = $article->benutzer_id; $post->created_at = $article->created_at; $post->updated_at = ($article->updated_at == $article->created_at) ? Carbon::createFromFormat(config('formats.datetime.database'), $article->updated_at)->addMinute() : $article->updated_at; $post->published = true; $post->save(); $controller = new ArticleController(); $publishDate = $controller->calculatePublicationDate($post, true); $publication = $post->publication('facebook'); $publication->setPublishDate($publishDate); $publication->noteForPublication(($publishDate > Carbon::now() ? true : false)); $publication->save(); $publication = $post->publication('twitter'); $publication->setPublishDate($publishDate); $publication->noteForPublication(($publishDate > Carbon::now() ? true : false)); $publication->save(); $publication = $post->publication('stadtanzeiger'); $publication->setPublishDate($publishDate); // $publication->noteForPublication(($publishDate > Carbon::now() ? true : false)); $publication->published_at = $publishDate; $publication->state = 'published'; $publication->save(); $migration = new PostMigration; $migration->type = $post->type; $migration->old_id = $article->id; $migration->post_id = $post->id; $migration->save(); $migrations = TagMigration::where('type', 'abteilung')->where('old_id', $article->abteilung_id)->get(); $tags = array(); foreach($migrations as $m) { $tags[] = $m->tag_id; } $migrations = TagMigration::where('type', 'instanz')->where('old_id', $article->instanz_id)->get(); foreach($migrations as $m) { $tags[] = $m->tag_id; } $post->tags()->sync($tags); $files = Storage::disk('import')->files('import/meldung/' . $article->id); $repo = new DocumentRepository(); $request = new Request(); foreach($files as $file) { $is_preview = false; if(basename($file) == $article->startbild) { $is_preview = true; } echo "ADD FILE $file \n"; $filedata = Storage::disk('import')->get($file); $extension = File::extension($file); $repo->upload('bericht', $post->id, basename($file), $extension, $filedata, $post->user_id, $is_preview); } } } } }