public static function handle($key, $val, $post) { if (!is_array($val)) { $val = [$val]; } $redirects = []; foreach ($val as $redirect_from) { $redirect = Post::where('slug', $redirect_from)->first(); if ($redirect && $redirect->type !== 'redirect') { echo '***********************************************************************' . "\n"; echo '* WARNING: Slug exists: ' . $redirect->slug . "\n"; echo '***********************************************************************' . "\n"; } $data = ['slug' => $redirect_from, 'title' => '', 'body' => '', 'type' => 'redirect', 'meta' => json_encode(['redirect_to' => $post->slug])]; if ($redirect) { $redirect->fill($data); if ($redirect->isDirty()) { $redirect->save(); echo 'Update Redirect: ' . $redirect_from . "\n"; } } else { $redirect = Post::create($data); echo 'New Redirect: ' . $redirect_from . "\n"; } array_push($redirects, $redirect->slug); } self::delete($redirects, $post); }
public function handle() { if (!($path = $this->folderExists())) { throw new Exception('Folder "' . $this->getFullPath() . '" does not exist'); } $files = File::files($path); $identifiers = []; foreach ($files as $file) { $fields = Parser::parse($file); if (!isset($fields['identifier'])) { $fields['identifier'] = explode('.', basename($file))[0]; } $data = Parser::process($fields); $post = Post::where('identifier', $data['identifier'])->first(); if ($post) { $post = $this->update($post, $data); } else { $post = $this->create($data); } array_push($identifiers, $post->identifier); Parser::handle($fields, $post); } $this->delete($identifiers); }
public static function count() { return Post::where('published_at', '<>', 'NULL')->where('type', 'post')->where('status', 'active')->count(); }