rainlab/blog-plugin

Publish many imports at once

Sforzando87 opened this issue · 8 comments

My imported posts (over 500) are not published after import, but I cannot sit and go through 500+ items one by one to publish them if the dates are already there. Please advise how to do it faster?

You could run the following code using php artisan tinker:

\RainLab\Blog\Models\Post::all()->each(function ($item) { 
   $item->update(['published'=>1]);
 });

But I agree that the "published" property should be added to the import/export models columns.

I get the following error:
image

It's probably because you are using the 1.0 branch...

try monkey patching the RainLab.Blog Post Model like this:

file: /plugins/rainlab/blog/models/Post.php:

public $fillable = ['published'];

Thank you for your assistance - I now get 'The slug has already been taken'

use this code instead: php artisan tinker

\RainLab\Blog\Models\Post::where('published', false)->update(['published' => true, 'published_at' => now()->toDateTimeString()]);

For your initial import did you include the published_at column?

I kind of got this to work - not the ideal solution but I used the following code in tinker:
\RainLab\Blog\Models\Post::where('published', false)->update(['published' => true, 'published_at' => now()->toDateTimeString()]);

I then re-imported the csv and updated the original post publish dates and all seems to be ok. Thanks for your help guys.