Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add post store args length dependency check #402

Merged
merged 1 commit into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion classes/ActionScheduler_DataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ActionScheduler_DataController {
* @return bool
*/
public static function dependencies_met() {
return version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' );
$php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' );
return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true );
}

/**
Expand Down
33 changes: 32 additions & 1 deletion classes/data-stores/ActionScheduler_wpPostStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store {
const POST_TYPE = 'scheduled-action';
const GROUP_TAXONOMY = 'action-group';
const SCHEDULE_META_KEY = '_action_manager_schedule';
const DEPENDENCIES_MET = 'as-post-store-dependencies-met';

/** @var DateTimeZone */
protected $local_timezone = NULL;
Expand Down Expand Up @@ -762,7 +763,12 @@ public function log_execution( $action_id ) {
$wpdb->query($sql);
}


/**
* Record that an action was completed.
*
* @param int $action_id ID of the completed action.
* @throws InvalidArgumentException|RuntimeException
*/
public function mark_complete( $action_id ) {
$post = get_post($action_id);
if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
Expand All @@ -781,6 +787,29 @@ public function mark_complete( $action_id ) {
}
}

/**
* Determine whether the post store can be migrated.
*
* @return bool
*/
public function migration_dependencies_met( $setting ) {
global $wpdb;

$dependencies_met = get_transient( self::DEPENDENCIES_MET );
if ( empty( $dependencies_met ) ) {
$found_action = $wpdb->get_var(
$wpdb->prepare(
"SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND CHAR_LENGTH(post_content) > 191 LIMIT 1",
self::POST_TYPE
)
);
$dependencies_met = $found_action ? 'no' : 'yes';
set_transient( self::DEPENDENCIES_MET, $dependencies_met, DAY_IN_SECONDS );
}

return 'yes' == $dependencies_met ? $setting : false;
}

/**
* InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4.
*
Expand All @@ -800,6 +829,8 @@ protected function validate_action( ActionScheduler_Action $action ) {
* @codeCoverageIgnore
*/
public function init() {
add_filter( 'action_scheduler_migration_dependencies_met', array( $this, 'migration_dependencies_met' ) );

$post_type_registrar = new ActionScheduler_wpPostStore_PostTypeRegistrar();
$post_type_registrar->register();

Expand Down