Skip to content

Commit

Permalink
Merge pull request #457 from publishpress/develop
Browse files Browse the repository at this point in the history
Release 3.0.1
  • Loading branch information
andergmartins authored Jun 15, 2023
2 parents 7ef30a4 + c358495 commit 6ff2552
Show file tree
Hide file tree
Showing 22 changed files with 504 additions and 76 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
"make-mo": "wp i18n make-mo ./languages ./languages",
"gh-cleanup-workflows": "user=publishpress repo=publishpress-future; gh api repos/$user/$repo/actions/runs --paginate -q '.workflow_runs[] | select(.head_branch != \"master\") | \"\\(.id)\"' | xargs -n1 -I % gh api --silent repos/$user/$repo/actions/runs/% -X DELETE",
"check:lint": "phplint",
"check:phpcs": "phpcs"
"check:phpcs": [
"@build:dir",
"phpcs"
]
},
"extra": {
"plugin-slug": "post-expirator",
Expand Down
14 changes: 11 additions & 3 deletions legacy/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PublishPress\Future\Modules\Expirator\Migrations\V30000ActionArgsSchema;
use PublishPress\Future\Modules\Expirator\Migrations\V30000ReplaceFooterPlaceholders;
use PublishPress\Future\Modules\Expirator\Migrations\V30000WPCronToActionsScheduler;
use PublishPress\Future\Modules\Expirator\Migrations\V30001RestorePostMeta;
use PublishPress\Future\Modules\Expirator\PostMetaAbstract;
use PublishPress\Future\Modules\Expirator\Schemas\ActionArgsSchema;

Expand Down Expand Up @@ -1009,12 +1010,19 @@ function postexpirator_upgrade()
}
}

if (version_compare($version, '3') === -1) {
$container->get(ServicesAbstract::CRON)->enqueueAsyncAction(V30000WPCronToActionsScheduler::HOOK);
if (version_compare($version, '3.0.0') === -1) {
$container->get(ServicesAbstract::CRON)->enqueueAsyncAction(V30000WPCronToActionsScheduler::HOOK, [], true);
$container->get(ServicesAbstract::HOOKS)->doAction(V30000ActionArgsSchema::HOOK);
// FIXME: Add migration from post meta to the args table.
$container->get(ServicesAbstract::HOOKS)->doAction(V30000ReplaceFooterPlaceholders::HOOK);
}

if (version_compare($version, '3.0.1') === -1) {
if (! get_option('pp_future_V30001RestorePostMeta')) {
$container->get(ServicesAbstract::CRON)->enqueueAsyncAction(V30001RestorePostMeta::HOOK, [], true);

update_option('pp_future_V30001RestorePostMeta', true);
}
}
}

$currentVersion = $container->get(ServicesAbstract::PLUGIN_VERSION);
Expand Down
4 changes: 2 additions & 2 deletions post-expirator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: http://wordpress.org/extend/plugins/post-expirator/
* Description: PublishPress Future allows you to schedule automatic changes to posts, pages and other content types.
* Author: PublishPress
* Version: 3.0.0
* Version: 3.0.1
* Author URI: http://publishpress.com
* Text Domain: post-expirator
* Domain Path: /languages
Expand All @@ -27,7 +27,7 @@
define('PUBLISHPRESS_FUTURE_LOADED', true);

if (! defined('PUBLISHPRESS_FUTURE_VERSION')) {
define('PUBLISHPRESS_FUTURE_VERSION', '3.0.0');
define('PUBLISHPRESS_FUTURE_VERSION', '3.0.1');
}

$vendorAutoloadPath = __DIR__ . '/vendor/autoload.php';
Expand Down
13 changes: 12 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Tags: expire posts, update posts, schedule changes, automatic changes,
Requires at least: 5.3
Requires PHP: 5.6
Tested up to: 6.2
Stable tag: 3.0.0
Stable tag: 3.0.1

Add an expiration date to posts. When your post is automatically unpublished, you can delete the post, change the status, or update the post categories.

Expand Down Expand Up @@ -140,6 +140,17 @@ Yes, the PublishPress Future plugin allows you to schedule automatic changes to

== Changelog ==

= [3.0.1] - [15 Jun, 2023] =

* ADDED: Add diagnostic check for DB schema in the Settings page;
* CHANGED: Changed privacy for method PublishPress\Future\Framework\WordPress\Models\PostModel::getPostInstance from `private` to `protected`;
* FIXED: Restore future action data on post meta fields, #452;
* FIXED: Fix PHP warning about undefined index 'categoryTaxonomy';
* FIXED: Fix auto-enabled future action on new posts, #447;
* FIXED: Fix default future action type on custom post types;
* FIXED: First letter of future actions log is not capitalized on some messages in the popup view;
* FIXED: Fix log message when actions related to taxonomy terms run;

= [3.0.0] - [13 Jun, 2023] =

* ADDED: Add Deutch translation files, #429;
Expand Down
57 changes: 51 additions & 6 deletions services.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
use PublishPress\Future\Modules\Expirator\ExpirationScheduler;
use PublishPress\Future\Modules\Expirator\HooksAbstract as ExpirationHooksAbstract;
use PublishPress\Future\Modules\Expirator\Interfaces\SchedulerInterface;
use PublishPress\Future\Modules\Expirator\Migrations\V30000ReplaceFooterPlaceholders;
use PublishPress\Future\Modules\Expirator\Migrations\V30000WPCronToActionsScheduler;
use PublishPress\Future\Modules\Expirator\Migrations\V30001RestorePostMeta;
use PublishPress\Future\Modules\Expirator\Models\ActionArgsModel;
use PublishPress\Future\Modules\Expirator\Models\CurrentUserModel;
use PublishPress\Future\Modules\Expirator\Models\DefaultDataModel;
Expand All @@ -52,6 +55,7 @@
use PublishPress\Future\Modules\Settings\SettingsFacade;
use PublishPress\Future\Modules\VersionNotices\Module as ModuleVersionNotices;
use PublishPress\Future\Modules\WooCommerce\Module as ModuleWooCommerce;
use PublishPressFuture\Modules\Expirator\Migrations\V30000ActionArgsSchema;

return [
ServicesAbstract::PLUGIN_VERSION => PUBLISHPRESS_FUTURE_VERSION,
Expand Down Expand Up @@ -261,7 +265,7 @@
$container->get(ServicesAbstract::ERROR),
$container->get(ServicesAbstract::LOGGER),
$container->get(ServicesAbstract::DATETIME),
$container->get(ServicesAbstract::POST_MODEL_FACTORY),
$container->get(ServicesAbstract::EXPIRABLE_POST_MODEL_FACTORY),
$container->get(ServicesAbstract::ACTION_ARGS_MODEL_FACTORY)
);
},
Expand Down Expand Up @@ -336,7 +340,8 @@
$container->get(ServicesAbstract::EXPIRATION_ACTIONS_MODEL),
$container->get(ServicesAbstract::CRON),
$container->get(ServicesAbstract::OPTIONS),
$container->get(ServicesAbstract::EXPIRABLE_POST_MODEL_FACTORY)
$container->get(ServicesAbstract::EXPIRABLE_POST_MODEL_FACTORY),
$container->get(ServicesAbstract::MIGRATIONS_FACTORY)
);
},

Expand Down Expand Up @@ -391,7 +396,8 @@
$container->get(ServicesAbstract::EMAIL),
$container->get(ServicesAbstract::TERM_MODEL_FACTORY),
$container->get(ServicesAbstract::EXPIRATION_ACTION_FACTORY),
$container->get(ServicesAbstract::ACTION_ARGS_MODEL_FACTORY)
$container->get(ServicesAbstract::ACTION_ARGS_MODEL_FACTORY),
$container->get(ServicesAbstract::DEFAULT_DATA_MODEL)
);
};
},
Expand Down Expand Up @@ -478,9 +484,9 @@
ServicesAbstract::SCHEDULED_ACTIONS_TABLE_FACTORY => static function (ContainerInterface $container) {
return function() use ($container) {
return new ScheduledActionsTable(
ActionScheduler::store(),
ActionScheduler::logger(),
ActionScheduler::runner(),
$container->get(ServicesAbstract::ACTION_SCHEDULER_STORE),
$container->get(ServicesAbstract::ACTION_SCHEDULER_LOGGER),
$container->get(ServicesAbstract::ACTION_SCHEDULER_RUNNER),
$container->get(ServicesAbstract::HOOKS)
);
};
Expand All @@ -493,4 +499,43 @@
);
};
},

ServicesAbstract::ACTION_SCHEDULER_STORE => static function (ContainerInterface $container) {
return ActionScheduler::store();
},

ServicesAbstract::ACTION_SCHEDULER_RUNNER => static function (ContainerInterface $container) {
return ActionScheduler::runner();
},

ServicesAbstract::ACTION_SCHEDULER_LOGGER => static function (ContainerInterface $container) {
return ActionScheduler::logger();
},

ServicesAbstract::MIGRATIONS_FACTORY => static function (ContainerInterface $container) {
return function () use ($container) {
return [
new V30000ActionArgsSchema(
$container->get(ServicesAbstract::CRON),
$container->get(ServicesAbstract::HOOKS)
),
new V30000WPCronToActionsScheduler(
$container->get(ServicesAbstract::CRON),
$container->get(ServicesAbstract::HOOKS),
$container->get(ServicesAbstract::EXPIRABLE_POST_MODEL_FACTORY)
),
new V30000ReplaceFooterPlaceholders(
$container->get(ServicesAbstract::HOOKS),
$container->get(ServicesAbstract::OPTIONS)
),
new V30001RestorePostMeta(
$container->get(ServicesAbstract::CRON),
$container->get(ServicesAbstract::HOOKS),
$container->get(ServicesAbstract::OPTIONS),
$container->get(ServicesAbstract::EXPIRABLE_POST_MODEL_FACTORY),
$container->get(ServicesAbstract::ACTION_SCHEDULER_STORE)
),
];
};
},
];
5 changes: 5 additions & 0 deletions src/Core/DI/ServicesAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace PublishPress\Future\Core\DI;

defined('ABSPATH') or die('Direct access not allowed.');

abstract class ServicesAbstract
{
const PLUGIN = 'future.free/plugin';
Expand Down Expand Up @@ -61,4 +62,8 @@ abstract class ServicesAbstract
const TAXONOMIES_MODEL_FACTORY = 'future.free/taxonomies-model-factory';
const SCHEDULED_ACTIONS_TABLE_FACTORY = 'future.free/scheduled-actions-table';
const ACTION_ARGS_MODEL_FACTORY = 'future.free/actions-args-mode-factory';
const ACTION_SCHEDULER_STORE = 'future.free/action-scheduler/store';
const ACTION_SCHEDULER_LOGGER = 'future.free/action-scheduler/logger';
const ACTION_SCHEDULER_RUNNER = 'future.free/action-scheduler/runner';
const MIGRATIONS_FACTORY = 'future.free/migrations';
}
2 changes: 1 addition & 1 deletion src/Framework/WordPress/Models/PostModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function postExists()
* @return WP_Post
* @throws \PublishPress\Future\Framework\WordPress\Exceptions\NonexistentPostException
*/
private function getPostInstance()
protected function getPostInstance()
{
if (empty($this->postInstance)) {
$this->postInstance = \get_post($this->getPostId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ public function getNotificationText()

return sprintf(
__(
'The following terms (%s) were removed from the %s: "%s". The new list of terms on the post is: %s.',
'The following terms (%s) were removed from the %s: %s. The new list of terms on the post is: %s.',
'post-expirator'
),
$this->log['expiration_taxonomy'],
$termsModel->getTermNamesByIdAsString($this->log['removed_terms'], $this->log['expiration_taxonomy']),
strtolower($this->postModel->getPostTypeSingularLabel()),
$termsModel->getTermNamesByIdAsString($this->log['removed_terms'], $this->log['expiration_taxonomy']),
$termsModel->getTermNamesByIdAsString($this->log['updated_terms'], $this->log['expiration_taxonomy'])
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public function getNotificationText()
'post-expirator'
),
$this->log['expiration_taxonomy'],
$termsModel->getTermNamesByIdAsString($this->log['updated_terms'], $this->log['expiration_taxonomy']),
strtolower($this->postModel->getPostTypeSingularLabel()),
$termsModel->getTermNamesByIdAsString($this->log['updated_terms'], $this->log['expiration_taxonomy']),
$termsModel->getTermNamesByIdAsString($this->log['original_terms'], $this->log['expiration_taxonomy'])
);
}
Expand Down
22 changes: 22 additions & 0 deletions src/Modules/Expirator/ExpirationScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use PublishPress\Future\Modules\Expirator\Interfaces\CronInterface;
use PublishPress\Future\Modules\Expirator\Interfaces\SchedulerInterface;

use function tad\WPBrowser\vendorDir;

defined('ABSPATH') or die('Direct access not allowed.');

class ExpirationScheduler implements SchedulerInterface
Expand Down Expand Up @@ -132,6 +134,17 @@ public function schedule($postId, $timestamp, $opts)
print_r($opts, true)
)
);

$postModelFactory = $this->postModelFactory;
$postModel = $postModelFactory($postId);

// Metadata is used by 3rd party plugins.
$postModel->updateMeta('_expiration-date-type', isset($opts['expireType']) ? $opts['expireType'] : '');
$postModel->updateMeta('_expiration-date-status', 'saved');
$postModel->updateMeta('_expiration-date-taxonomy', isset($opts['categoryTaxonomy']) ? $opts['categoryTaxonomy'] : '');
$postModel->updateMeta('_expiration-date-categories', isset($opts['category']) ? $opts['category'] : '');
$postModel->updateMeta('_expiration-date', $timestamp);
$postModel->updateMeta('_expiration-date-options', $opts);
}

private function unscheduleIfScheduled($postId, $timestamp)
Expand Down Expand Up @@ -174,6 +187,15 @@ public function unschedule($postId)
$message = $postId . ' -> CLEARED SCHEDULED ACTION using ' . $this->cron->getIdentifier() . ', ' . $errorFeedback;

$this->logger->debug($message);

$this->deleteExpirationPostMeta($postId);
}
}

protected function deleteExpirationPostMeta($postId)
{
$postModelFactory = $this->postModelFactory;
$postModel = $postModelFactory($postId);
$postModel->deleteExpirationPostMeta();
}
}
1 change: 1 addition & 0 deletions src/Modules/Expirator/HooksAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class HooksAbstract
const ACTION_MIGRATE_REPLACE_FOOTER_PLACEHOLDERS = 'publishpress_future/v30000_replace_footer_placeholders';
const ACTION_MIGRATE_WPCRON_EXPIRATIONS = 'publishpress_future/v30000_migrate_wpcron_expirations';
const ACTION_MIGRATE_CREATE_ACTION_ARGS_SCHEMA = 'publishpress_future/v30000_create_actions_args_schema';
const ACTION_MIGRATE_RESTORE_POST_META = 'publishpress_future/v30001_restore_post_meta';
const ACTION_SCHEDULER_DELETED_ACTION = 'action_scheduler_deleted_action';
const ACTION_SCHEDULER_CANCELED_ACTION = 'action_scheduler_canceled_action';
const ACTION_SCHEDULER_AFTER_EXECUTE = 'action_scheduler_after_execute';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ public function migrate()

do_action(ExpiratorHooks::ACTION_SCHEDULE_POST_EXPIRATION, $postId, $eventData['time'], $args);

$postModel->deleteMeta('_expiration-date-type');
$postModel->deleteMeta('_expiration-date-status');
$postModel->deleteMeta('_expiration-date-taxonomy');
$postModel->deleteMeta('_expiration-date-categories');
$postModel->deleteMeta('_expiration-date');
$postModel->deleteMeta('_expiration-date-options');

wp_unschedule_event($eventData['time'], $eventData['hook'], $eventData['args']);
}
}
Expand Down
Loading

0 comments on commit 6ff2552

Please sign in to comment.