Skip to content

Commit 3918214

Browse files
Corrects composer.json
1 parent cd22b7f commit 3918214

File tree

7 files changed

+96
-87
lines changed

7 files changed

+96
-87
lines changed

batch-tasks.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

bootstrap.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace Underpin\Batch_Tasks;
4+
5+
use Underpin\Abstracts\Underpin;
6+
7+
if ( ! defined( 'ABSPATH' ) ) {
8+
exit;
9+
}
10+
11+
function batch_task_handler() {
12+
return Underpin::make_class( [
13+
'root_namespace' => 'Underpin\Batch_Tasks',
14+
'text_domain' => 'underpin-batch-tasks',
15+
'minimum_php_version' => '7.0',
16+
'minimum_wp_version' => '5.1',
17+
'version' => '1.0.0',
18+
] )->get( __FILE__ );
19+
}
20+
21+
//set up handler
22+
batch_task_handler();
23+
24+
// Enqueue scripts and styles to batch task.
25+
Underpin::attach( 'setup', new \Underpin\Factories\Observer( 'batch_tasks', [
26+
'update' => function ( Underpin $plugin ) {
27+
28+
// Register core-specific items.
29+
if ( $plugin->file() === __FILE__ ) {
30+
$dir_url = plugin_dir_url( __FILE__ );
31+
32+
// Register the batch JS
33+
$plugin->scripts()->add( 'batch', [
34+
'class' => 'Underpin\Scripts\Factories\Script_Instance',
35+
'args' => [
36+
[
37+
'handle' => 'underpin_batch',
38+
'deps' => [ 'jquery' ],
39+
'description' => 'Script that handles batch tasks.',
40+
'name' => "Batch Task Runner Script",
41+
'in_footer' => true,
42+
'src' => $plugin->url() . 'assets/js/build/batch.min.js',
43+
'version' => '1.0.0',
44+
],
45+
],
46+
] );
47+
48+
// Localize the ajax URL on the batch JS, if it was registered successfully.
49+
if ( ! is_wp_error( $plugin->scripts()->get( 'batch' ) ) ) {
50+
$plugin->scripts()->get( 'batch' )->set_param( 'ajaxUrl', admin_url( 'admin-ajax.php' ) );
51+
}
52+
53+
// Register the batch stylesheet
54+
$plugin->styles()->add( 'batch', [
55+
'class' => 'Underpin\Styles\Factories\Style_Instance',
56+
'args' => [
57+
[
58+
'handle' => 'underpin_batch',
59+
'description' => 'Styles for batch tasks.',
60+
'name' => "Batch Task Runner Styles",
61+
'src' => $dir_url . 'assets/css/build/batchStyle.min.css',
62+
],
63+
],
64+
] );
65+
}
66+
}
67+
] ) );
68+
69+
// Add this loader.
70+
Underpin::attach( 'setup', new \Underpin\Factories\Observers\Loader( 'batch_tasks', [
71+
'class' => 'Underpin\Batch_Tasks\Loaders\Batch_Tasks',
72+
] ) );

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"underpin/style-loader": "^1.0"
1616
},
1717
"autoload": {
18+
"psr-4": {"Underpin\\Batch_Tasks\\": "lib/"},
1819
"files": [
19-
"batch-tasks.php"
20+
"bootstrap.php"
2021
]
2122
}
2223
}
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
*/
88

99

10-
namespace Underpin_Batch_Tasks\Abstracts;
10+
namespace Underpin\Batch_Tasks\Abstracts;
1111

1212

13+
use Underpin\Loaders\Logger;
1314
use Underpin\Traits\Templates;
1415
use WP_Error;
15-
use function Underpin\underpin;
16+
use function Underpin\Batch_Tasks\batch_task_handler;
17+
1618

1719
if ( ! defined( 'ABSPATH' ) ) {
1820
exit;
@@ -180,7 +182,7 @@ public function run( $current_tally ) {
180182

181183
$this->finish_process( $current_tally );
182184

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

195197
if ( is_wp_error( $status ) ) {
196-
underpin()->logger()->log_wp_error( 'batch_error', $status );
198+
Logger::log_wp_error( 'batch_error', $status );
197199

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

201-
underpin()->logger()->log(
203+
Logger::log(
202204
'warning',
203205
'batch_action_stopped_early',
204206
'The batch action called ' . $this->name . ' stopped early because of an error.',
@@ -240,7 +242,7 @@ protected function is_done( $current_tally ) {
240242
protected function is_valid() {
241243

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

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

283-
underpin()->scripts()->set_param( 'batch', $this->batch_id, $batch_params );
284-
underpin()->scripts()->enqueue( 'batch' );
285-
underpin()->styles()->enqueue( 'batch' );
285+
batch_task_handler()->scripts()->set_param( 'batch', $this->batch_id, $batch_params );
286+
batch_task_handler()->scripts()->enqueue( 'batch' );
287+
batch_task_handler()->styles()->enqueue( 'batch' );
286288
echo $this->get_template( 'notice', [
287289
'batch_id' => $this->batch_id,
288290
'message' => $this->notice_message,
289291
'button_text' => $this->button_text,
290292
] );
291293

292-
underpin()->logger()->log(
294+
Logger::log(
293295
'notice',
294296
'batch_task_enqueued',
295297
'A batch task was enqueued.',
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88

99

10-
namespace Underpin_Batch_Tasks\Factories;
10+
namespace Underpin\Batch_Tasks\Factories;
1111

1212

13-
use Underpin_Batch_Tasks\Abstracts\Batch_Task;
13+
use Underpin\Batch_Tasks\Abstracts\Batch_Task;
1414
use Underpin\Traits\Instance_Setter;
1515

1616
if ( ! defined( 'ABSPATH' ) ) {
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
*/
88

99

10-
namespace Underpin_Batch_Tasks\Loaders;
10+
namespace Underpin\Batch_Tasks\Loaders;
1111

1212
use Underpin\Abstracts\Registries\Object_Registry;
13-
use Underpin_Batch_Tasks\Abstracts\Batch_Task;
13+
use Underpin\Loaders\Logger;
14+
use Underpin\Batch_Tasks\Abstracts\Batch_Task;
1415
use WP_Error;
15-
use function Underpin\underpin;
16+
1617

1718
if ( ! defined( 'ABSPATH' ) ) {
1819
exit;
@@ -30,9 +31,9 @@ class Batch_Tasks extends Object_Registry {
3031
/**
3132
* @inheritDoc
3233
*/
33-
protected $abstraction_class = 'Underpin_Batch_Tasks\Abstracts\Batch_Task';
34+
protected $abstraction_class = 'Underpin\Batch_Tasks\Abstracts\Batch_Task';
3435

35-
protected $default_factory = 'Underpin_Batch_Tasks\Factories\Batch_Task_Instance';
36+
protected $default_factory = 'Underpin\Batch_Tasks\Factories\Batch_Task_Instance';
3637

3738
/**
3839
* @inheritDoc
@@ -63,7 +64,7 @@ public function enqueue( $key ) {
6364
$batch_task = $this->get( $key );
6465

6566
if ( is_wp_error( $batch_task ) ) {
66-
underpin()->logger()->log_wp_error( 'error', $batch_task );
67+
Logger::log_wp_error( 'error', $batch_task );
6768

6869
return $batch_task;
6970
}

templates/batch/notice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
exit;
1212
}
1313

14-
if ( ! isset( $template ) || ! $template instanceof Underpin_Batch_Tasks\Abstracts\Batch_Task ) {
14+
if ( ! isset( $template ) || ! $template instanceof Underpin\Batch_Tasks\Abstracts\Batch_Task ) {
1515
return;
1616
}
1717

0 commit comments

Comments
 (0)