table('posts')->where('type', 'dienst')->delete(); } $services = DB::connection('mysql_alt')->select("SELECT * FROM ikarus_dienst ORDER BY 'id'"); foreach($services as $service) { // 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', 'dienst')->where('old_id', $service->id)->get(); if(($mode == 'replace') || ($mode == 'update' && $checkMigration->count() == 0)) { $new_user = User::find($service->benutzer_id); if(!$new_user) { $service->benutzer_id = 1; $new_user = User::find($service->benutzer_id); } \Auth::login($new_user); echo "INSERT service: $service->id\n"; $post = new Post; $post->type = 'dienst'; $post->title = ''; $post->datetime = $service->datum . " " . $service->uhrzeit; // $post->datetime = Carbon::parse($post->datetime)->addYears(2); $post->content = json_encode([ 'beschreibung' => MigrationHelper::normalize($service->beschreibung), 'ort' => $service->ort, ]); $post->user_id = $service->benutzer_id; $post->created_at = $service->created_at; $post->updated_at = ($service->updated_at == $service->created_at) ? Carbon::createFromFormat(config('formats.datetime.database'), $service->updated_at)->addMinute() : $service->updated_at; $post->published = true; $post->save(); $controller = new ServiceController(); $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 = $service->id; $migration->post_id = $post->id; $migration->save(); $migrations = TagMigration::where('type', 'abteilung')->where('old_id', $service->abteilung_id)->get(); $tags = array(); foreach($migrations as $m) { $tags[] = $m->tag_id; } $migrations = TagMigration::where('type', 'instanz')->where('old_id', $service->instanz_id)->get(); foreach($migrations as $m) { $tags[] = $m->tag_id; } $migrations = TagMigration::where('type', 'dienstart')->where('old_id', $service->dienstart_id)->get(); foreach($migrations as $m) { $tags[] = $m->tag_id; } $post->tags()->sync($tags); $post = Post::with('tags')->find($post->id); $post->save([ 'slug_update' => true, 'timestamps' => false ]); } } } }