victorjonsson / Arlima

Article List Manager - Wordpress plugin suitable for online newspapers that's in need of a fully customizable front page
28 stars 16 forks source link

Scheduled list versions that are added and then deleted will still get published #85

Closed aaslun closed 9 years ago

aaslun commented 9 years ago

It seems that scheduled deleted lists will still get published at the time of schedule even if they are deleted. The deleted list that gets published will be blank though. I'm looking into it in https://github.com/aaslun/Arlima/tree/schedule-bug-fix.

victorjonsson commented 9 years ago

God catch!

victorjonsson commented 9 years ago

You will not have to create a PR for this when you find the bug. This is fixed in my local version that is not yet pushed

/**
     * Publishes a scheduled arlima list
     * @param int $list_id
     * @param int $version_id
     */
    public static function publishScheduledList($list_id, $version_id)
    {
        $ver_repo = new Arlima_ListVersionRepository();
        $list = Arlima_List::builder()
                        ->id($list_id)
                        ->version($version_id)
                        ->includeFutureArticles()
                        ->build();

        if( $list->numArticles() > 0 ) {
            // No articles would mean that the version did not exist (todo: how should one detect that a requested version does not exist)
            $ver_repo->delete($version_id);
            $ver_repo->create($list, $list->getArticles(), $list->getVersionAttribute('user_id')); // Publish the list as a new version
        }
    }
aaslun commented 9 years ago

Great!! Thanks! :smile:

aaslun commented 9 years ago

Ah, just noticed this: the Arlima_ListVersionRepository is not yet available to me (guess it is still in your local version), but your code snippet still provides an approach for solving this using the Arlima_ListFactory until your release.