diff --git a/.gitignore b/.gitignore index 93cab34..f6add58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules yarn-error.log +.php_cs.cache diff --git a/README.md b/README.md index f94d0ce..6fd2fd0 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ add_filter('ramsey-batch-table-columns', function ($columns) { $columns[] = [ 'id' => 'columnHeaderID', 'name' => 'Custom Column Name', - 'contentKey' => 'jobArrayKeyFromWhereToPullContent', + 'contentKey' => 'myColumnNameOrSlug', ]; return $columns; }); @@ -225,7 +225,7 @@ The content of that newly registered column can be accessed by adding a new key ```php add_filter('ramsey-batch-jobs', function ($jobs, $instance) { - $jobs['MyAppNamespace\Batch\YourJob']['jobArrayKeyFromWhereToPullContent'] = ' + $jobs['MyAppNamespace\Batch\YourJob']['myColumnNameOrSlug'] = ' '; diff --git a/src/BatchJob.php b/src/BatchJob.php index 87d9a73..d0fe952 100644 --- a/src/BatchJob.php +++ b/src/BatchJob.php @@ -1,8 +1,8 @@ items = []; $this->lastRunTimes = get_option(RB_PLUGIN_SLUG . '_batch-run-timestamps', []); } @@ -44,23 +45,28 @@ public function __construct() { * Get batch items * @return obj|array Iterable object or array */ - public function getItems() { + public function getItems() + { return $this->items; } /** * Check if batch items are available */ - public function hasItems() { - return !empty( $this->getItems() ); + public function hasItems() + { + return !empty($this->getItems()); } /** * Check if the batch name is allowed to run based on the instantiated class. * @return boolean */ - public function isAllowedBatch() { - if( empty($_REQUEST) || !array_key_exists('batchName', $_REQUEST) ) return false; + public function isAllowedBatch() + { + if (empty($_REQUEST) || !array_key_exists('batchName', $_REQUEST)) { + return false; + } return stripslashes($_REQUEST['batchName']) == get_class($this); } @@ -69,8 +75,9 @@ public function isAllowedBatch() { * Get the timestamp corresponding to the time this particular batch was last run. * @return float Timestamp */ - public function getLastRunTime() { - if( empty($this->lastRunTimes) || !array_key_exists(get_called_class(), $this->lastRunTimes) ) { + public function getLastRunTime() + { + if (empty($this->lastRunTimes) || !array_key_exists(get_called_class(), $this->lastRunTimes)) { return ''; } @@ -83,8 +90,11 @@ public function getLastRunTime() { * @param string $default Default string if batch has never been run * @return string */ - public function getLastRunDate($format = 'M j, Y H:i:s', $default = '--') { - if( !$this->getLastRunTime() ) return $default; + public function getLastRunDate($format = 'M j, Y H:i:s', $default = '--') + { + if (!$this->getLastRunTime()) { + return $default; + } return date($format, $this->getLastRunTime()); } @@ -93,12 +103,12 @@ public function getLastRunDate($format = 'M j, Y H:i:s', $default = '--') { * @param float $timestamp A PHP timestamp * @return bool True if option value has changed, false if not or if update failed. */ - protected function updateLastRunDate($timestamp = null) { - if( !$timestamp ) { + protected function updateLastRunDate($timestamp = null) + { + if (!$timestamp) { $timestamp = current_time('timestamp'); } $this->lastRunTimes[get_called_class()] = $timestamp; return update_option(RB_PLUGIN_SLUG . '_batch-run-timestamps', $this->lastRunTimes, false); } - } diff --git a/src/Controllers/BatchController.php b/src/Controllers/BatchController.php index 5ca385e..3a29fdf 100644 --- a/src/Controllers/BatchController.php +++ b/src/Controllers/BatchController.php @@ -1,43 +1,51 @@ jobs = apply_filters(RB_PLUGIN_SLUG . '-jobs', [], $this); } - public static function runJob() { - if( !wp_doing_ajax() || $_REQUEST['action'] != RB_PLUGIN_SLUG ) return; + public static function runJob() + { + if (!wp_doing_ajax() || $_REQUEST['action'] != RB_PLUGIN_SLUG) { + return; + } $currentBatchName = stripslashes($_REQUEST['batchName']); $batchObj = $GLOBALS[RB_PLUGIN_SLUG][$currentBatchName]; - if( !$batchObj ) { + if (!$batchObj) { wp_send_json_error(['reason' => "Attempted to run job but global object not found - {$currentBatchName}."]); } $batchObj->run(); } - public static function runJobItem() { - if( !wp_doing_ajax() || $_REQUEST['action'] != 'ramsey-batch-item' ) return; + public static function runJobItem() + { + if (!wp_doing_ajax() || $_REQUEST['action'] != 'ramsey-batch-item') { + return; + } $currentBatchName = stripslashes($_REQUEST['batchName']); $batchObj = $GLOBALS[RB_PLUGIN_SLUG][$currentBatchName]; - if( !$batchObj ) { + if (!$batchObj) { wp_send_json_error(['reason' => "Attempted to run job item but global object not found - {$currentBatchName}."]); } @@ -48,17 +56,21 @@ public static function runJobItem() { * Enqueue JS scripts * @return void */ - public static function enqueueScripts() { + public static function enqueueScripts() + { wp_register_script(RB_PLUGIN_SLUG, RB_PLUGIN_URL . '/js/dist/ramsey-batch.min.js', ['jquery'], get_plugin_data(RB_PLUGIN_ROOT . '/wp-ramsey-batch.php', false)['Version']); $currentScreen = get_current_screen(); - if( $currentScreen->id == 'tools_page_' . RB_PLUGIN_SLUG) { + if ($currentScreen->id == 'tools_page_' . RB_PLUGIN_SLUG) { wp_enqueue_script(RB_PLUGIN_SLUG); } } - public static function register(string $name) { - if( !class_exists($name) ) return; + public static function register(string $name) + { + if (!class_exists($name)) { + return; + } $obj = new $name; add_filter('ramsey-batch-jobs', [$obj, 'registerBatchJob']); @@ -66,8 +78,8 @@ public static function register(string $name) { $GLOBALS[RB_PLUGIN_SLUG][$name] = $obj; } - public function getJobs() { - return $this->jobs; + public function getJobs() + { + return $this->jobs; } - } diff --git a/src/Views/AdminPage.php b/src/Views/AdminPage.php index 4dd6c1b..8416a7a 100644 --- a/src/Views/AdminPage.php +++ b/src/Views/AdminPage.php @@ -1,35 +1,38 @@ controller = $controller; - $this->slug = $slug; - $this->title = $title; - } - - protected function open() { - return '
The batch jobs here are powerful and must be run with caution. It's likely that they will irreversibly change your data. Carefully read and understand each job's description before proceeding.
@@ -51,26 +52,27 @@ public function display() { |
---|