Skip to content

Commit

Permalink
add post store args length dependency check
Browse files Browse the repository at this point in the history
  • Loading branch information
rrennick committed Dec 10, 2019
1 parent 5ff66f7 commit 727a589
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
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 > 0 ? '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

0 comments on commit 727a589

Please sign in to comment.