Skip to content

Commit

Permalink
Corrects composer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstandiford committed Nov 23, 2021
1 parent cd22b7f commit 3918214
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 87 deletions.
67 changes: 0 additions & 67 deletions batch-tasks.php

This file was deleted.

72 changes: 72 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Underpin\Batch_Tasks;

use Underpin\Abstracts\Underpin;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

function batch_task_handler() {
return Underpin::make_class( [
'root_namespace' => 'Underpin\Batch_Tasks',
'text_domain' => 'underpin-batch-tasks',
'minimum_php_version' => '7.0',
'minimum_wp_version' => '5.1',
'version' => '1.0.0',
] )->get( __FILE__ );
}

//set up handler
batch_task_handler();

// Enqueue scripts and styles to batch task.
Underpin::attach( 'setup', new \Underpin\Factories\Observer( 'batch_tasks', [
'update' => function ( Underpin $plugin ) {

// Register core-specific items.
if ( $plugin->file() === __FILE__ ) {
$dir_url = plugin_dir_url( __FILE__ );

// Register the batch JS
$plugin->scripts()->add( 'batch', [
'class' => 'Underpin\Scripts\Factories\Script_Instance',
'args' => [
[
'handle' => 'underpin_batch',
'deps' => [ 'jquery' ],
'description' => 'Script that handles batch tasks.',
'name' => "Batch Task Runner Script",
'in_footer' => true,
'src' => $plugin->url() . 'assets/js/build/batch.min.js',
'version' => '1.0.0',
],
],
] );

// Localize the ajax URL on the batch JS, if it was registered successfully.
if ( ! is_wp_error( $plugin->scripts()->get( 'batch' ) ) ) {
$plugin->scripts()->get( 'batch' )->set_param( 'ajaxUrl', admin_url( 'admin-ajax.php' ) );
}

// Register the batch stylesheet
$plugin->styles()->add( 'batch', [
'class' => 'Underpin\Styles\Factories\Style_Instance',
'args' => [
[
'handle' => 'underpin_batch',
'description' => 'Styles for batch tasks.',
'name' => "Batch Task Runner Styles",
'src' => $dir_url . 'assets/css/build/batchStyle.min.css',
],
],
] );
}
}
] ) );

// Add this loader.
Underpin::attach( 'setup', new \Underpin\Factories\Observers\Loader( 'batch_tasks', [
'class' => 'Underpin\Batch_Tasks\Loaders\Batch_Tasks',
] ) );
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
"underpin/style-loader": "^1.0"
},
"autoload": {
"psr-4": {"Underpin\\Batch_Tasks\\": "lib/"},
"files": [
"batch-tasks.php"
"bootstrap.php"
]
}
}
22 changes: 12 additions & 10 deletions lib/abstracts/Batch_Task.php → lib/Abstracts/Batch_Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
*/


namespace Underpin_Batch_Tasks\Abstracts;
namespace Underpin\Batch_Tasks\Abstracts;


use Underpin\Loaders\Logger;
use Underpin\Traits\Templates;
use WP_Error;
use function Underpin\underpin;
use function Underpin\Batch_Tasks\batch_task_handler;


if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down Expand Up @@ -180,7 +182,7 @@ public function run( $current_tally ) {

$this->finish_process( $current_tally );

underpin()->logger()->log(
Logger::log(
'notice',
'batch_action_complete',
'The batch action called ' . $this->name . ' is complete.',
Expand All @@ -193,12 +195,12 @@ public function run( $current_tally ) {
$status = $this->task( $current_tally, $i );

if ( is_wp_error( $status ) ) {
underpin()->logger()->log_wp_error( 'batch_error', $status );
Logger::log_wp_error( 'batch_error', $status );

// Bail early if we're supposed to stop when an error occurs.
if ( true === $this->stop_on_error ) {

underpin()->logger()->log(
Logger::log(
'warning',
'batch_action_stopped_early',
'The batch action called ' . $this->name . ' stopped early because of an error.',
Expand Down Expand Up @@ -240,7 +242,7 @@ protected function is_done( $current_tally ) {
protected function is_valid() {

if ( ! current_user_can( $this->capability ) ) {
return underpin()->logger()->log_as_error(
return Logger::log_as_error(
'batch_error',
'batch_task_invalid_user_permissions',
'The specified user does not have the permission to run this task'
Expand Down Expand Up @@ -280,16 +282,16 @@ public function render_callback() {

$batch_params = [ 'total_items' => $this->total_items ];

underpin()->scripts()->set_param( 'batch', $this->batch_id, $batch_params );
underpin()->scripts()->enqueue( 'batch' );
underpin()->styles()->enqueue( 'batch' );
batch_task_handler()->scripts()->set_param( 'batch', $this->batch_id, $batch_params );
batch_task_handler()->scripts()->enqueue( 'batch' );
batch_task_handler()->styles()->enqueue( 'batch' );
echo $this->get_template( 'notice', [
'batch_id' => $this->batch_id,
'message' => $this->notice_message,
'button_text' => $this->button_text,
] );

underpin()->logger()->log(
Logger::log(
'notice',
'batch_task_enqueued',
'A batch task was enqueued.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*/


namespace Underpin_Batch_Tasks\Factories;
namespace Underpin\Batch_Tasks\Factories;


use Underpin_Batch_Tasks\Abstracts\Batch_Task;
use Underpin\Batch_Tasks\Abstracts\Batch_Task;
use Underpin\Traits\Instance_Setter;

if ( ! defined( 'ABSPATH' ) ) {
Expand Down
13 changes: 7 additions & 6 deletions lib/loaders/Batch_Tasks.php → lib/Loaders/Batch_Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
*/


namespace Underpin_Batch_Tasks\Loaders;
namespace Underpin\Batch_Tasks\Loaders;

use Underpin\Abstracts\Registries\Object_Registry;
use Underpin_Batch_Tasks\Abstracts\Batch_Task;
use Underpin\Loaders\Logger;
use Underpin\Batch_Tasks\Abstracts\Batch_Task;
use WP_Error;
use function Underpin\underpin;


if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -30,9 +31,9 @@ class Batch_Tasks extends Object_Registry {
/**
* @inheritDoc
*/
protected $abstraction_class = 'Underpin_Batch_Tasks\Abstracts\Batch_Task';
protected $abstraction_class = 'Underpin\Batch_Tasks\Abstracts\Batch_Task';

protected $default_factory = 'Underpin_Batch_Tasks\Factories\Batch_Task_Instance';
protected $default_factory = 'Underpin\Batch_Tasks\Factories\Batch_Task_Instance';

/**
* @inheritDoc
Expand Down Expand Up @@ -63,7 +64,7 @@ public function enqueue( $key ) {
$batch_task = $this->get( $key );

if ( is_wp_error( $batch_task ) ) {
underpin()->logger()->log_wp_error( 'error', $batch_task );
Logger::log_wp_error( 'error', $batch_task );

return $batch_task;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/batch/notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
exit;
}

if ( ! isset( $template ) || ! $template instanceof Underpin_Batch_Tasks\Abstracts\Batch_Task ) {
if ( ! isset( $template ) || ! $template instanceof Underpin\Batch_Tasks\Abstracts\Batch_Task ) {
return;
}

Expand Down

0 comments on commit 3918214

Please sign in to comment.