Skip to content

Commit 55f0ae7

Browse files
authored
Merge pull request #10 from stellarwp/fix/sql-table-definition-for-dbDelta
Updates table schema and fixes SQL generation
2 parents 26b945b + b4f5b44 commit 55f0ae7

File tree

9 files changed

+28
-22
lines changed

9 files changed

+28
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard.
44

5+
## [0.0.3] 2025-07-31
6+
7+
* Fix - Removed an empty line after the columns and before the primary key of the Table creation SQL.
8+
9+
[0.0.3]: https://github.com/stellarwp/shepherd/releases/tag/0.0.3
10+
511
## [0.0.2] 2025-07-14
612

713
* Fix - Fix the path to the Action Scheduler file to take into consideration the different ways Composer can be installed.

shepherd.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @wordpress-plugin
1010
* Plugin Name: Shepherd
1111
* Description: A library for offloading tasks to background processes.
12-
* Version: 0.0.2
12+
* Version: 0.0.3
1313
* Author: StellarWP
1414
* Author URI: https://stellarwp.com
1515
* License: GPL-2.0-or-later

src/Abstracts/Table_Abstract.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ protected function check_and_add_index( array $results, string $index_name, stri
227227
* by the `dbDelta` function.
228228
*
229229
* @since 0.0.1
230+
* @since 0.0.3 Updated to remove an empty line after the columns and before the primary key.
230231
*
231232
* @return string The table creation SQL, in the format supported
232233
* by the `dbDelta` function.
@@ -264,11 +265,11 @@ public function get_definition() {
264265
$columns_definitions[] = $column_sql;
265266
}
266267

267-
$columns_sql = implode( ',' . PHP_EOL, $columns_definitions ) . ',' . PHP_EOL;
268+
$columns_sql = implode( ',' . PHP_EOL, $columns_definitions );
268269

269270
return "
270271
CREATE TABLE `{$table_name}` (
271-
{$columns_sql}
272+
{$columns_sql},
272273
PRIMARY KEY (`{$uid_column}`)
273274
) {$charset_collate};
274275
";

src/Tables/Task_Logs.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ class Task_Logs extends Table {
5252
* The schema version.
5353
*
5454
* @since 0.0.1
55+
* @since 0.0.3 Updated to 0.0.3.
5556
*
5657
* @var string
5758
*/
58-
const SCHEMA_VERSION = '0.0.2-dev';
59+
const SCHEMA_VERSION = '0.0.3';
5960

6061
/**
6162
* The base table name, without the table prefix.

src/Tables/Tasks.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ class Tasks extends Table {
4747
* The schema version.
4848
*
4949
* @since 0.0.1
50+
* @since 0.0.3 Updated to 0.0.2.
5051
*
5152
* @var string
5253
*/
53-
const SCHEMA_VERSION = '0.0.1-dev';
54+
const SCHEMA_VERSION = '0.0.2s';
5455

5556
/**
5657
* The base table name, without the table prefix.

tests/integration/Herding_Test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ public function it_should_only_clean_orphaned_tasks_not_active_ones(): void {
268268
$shepherd->dispatch( $task1 );
269269
$task_id_1 = $shepherd->get_last_scheduled_task_id();
270270

271+
// Execute first task
272+
$this->assertTaskExecutesWithoutErrors( $task_id_1 );
273+
271274
$task2 = new Do_Action_Task( 'arg2' );
272275
$shepherd->dispatch( $task2 );
273276
$task_id_2 = $shepherd->get_last_scheduled_task_id();
274277

275278
$this->assertNotEquals( $task_id_1, $task_id_2 );
276279

277-
// Execute first task
278-
$this->assertTaskExecutesWithoutErrors( $task_id_1 );
279-
280280
// Manually remove only the first task's action from Action Scheduler
281281
DB::query(
282282
DB::prepare(

tests/integration/Provider_Test.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public function it_should_delete_multiple_tasks_for_same_action(): void {
102102
$task_id_2 = $shepherd->get_last_scheduled_task_id();
103103

104104
$this->assertTaskExecutesWithoutErrors( $task_id_1 );
105-
$this->assertTaskExecutesWithoutErrors( $task_id_2 );
106105

107106
// Manually set both tasks to have the same action_id for testing.
108107
$common_action_id = $task1->get_action_id();
@@ -126,6 +125,7 @@ public function it_should_delete_multiple_tasks_for_same_action(): void {
126125
$task_id_2
127126
)
128127
);
128+
129129
$this->assertEquals( 2, $tasks_count_before );
130130

131131
$this->delete_tasks_action( $task1 );
@@ -177,11 +177,12 @@ public function it_should_only_delete_tasks_for_specified_action(): void {
177177
$shepherd->dispatch( $task1 );
178178
$task_id_1 = $shepherd->get_last_scheduled_task_id();
179179

180+
$this->assertTaskExecutesWithoutErrors( $task_id_1 );
181+
180182
$task2 = new Do_Action_Task( 'arg2' );
181183
$shepherd->dispatch( $task2 );
182184
$task_id_2 = $shepherd->get_last_scheduled_task_id();
183185

184-
$this->assertTaskExecutesWithoutErrors( $task_id_1 );
185186
$this->assertTaskExecutesWithoutErrors( $task_id_2 );
186187

187188
$this->delete_tasks_action( $task1 );

tests/integration/Tasks/Email_Test.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,17 @@ public function it_should_schedule_multiple_tasks_with_different_args(): void {
233233
$task1_id = $shepherd->get_last_scheduled_task_id();
234234
$this->assertIsInt( $task1_id );
235235

236+
$this->assertTaskExecutesWithoutErrors( $task1_id );
237+
236238
$task2 = new Email( 'test2@test.com', 'subject2', 'body2' );
237239
$shepherd->dispatch( $task2 );
238240
$task2_id = $shepherd->get_last_scheduled_task_id();
239241
$this->assertIsInt( $task2_id );
240242

241-
$this->assertNotEquals( $task1_id, $task2_id );
242-
243-
$hook_name = 'shepherd_' . tests_shepherd_get_hook_prefix() . '_task_already_scheduled';
244-
$this->assertSame( 0, did_action( $hook_name ) );
245-
246-
$this->assertTaskExecutesWithoutErrors( $task1_id );
247243
$this->assertTaskExecutesWithoutErrors( $task2_id );
248244

245+
$this->assertNotEquals( $task1_id, $task2_id );
246+
249247
$this->assertCount( 2, $spy );
250248
$this->assertSame( [ 'test1@test.com', 'subject1', 'body1', [], [] ], $spy[0] );
251249
$this->assertSame( [ 'test2@test.com', 'subject2', 'body2', [], [] ], $spy[1] );

tests/integration/Tasks/HTTP_Request_Test.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,19 +382,17 @@ public function it_should_schedule_different_requests_separately(): void {
382382
$task1_id = $shepherd->get_last_scheduled_task_id();
383383
$this->assertIsInt( $task1_id );
384384

385+
$this->assertTaskExecutesWithoutErrors( $task1_id );
386+
385387
$task2 = new HTTP_Request( 'https://api2.example.com/endpoint' );
386388
$shepherd->dispatch( $task2 );
387389
$task2_id = $shepherd->get_last_scheduled_task_id();
388390
$this->assertIsInt( $task2_id );
389391

390-
$this->assertNotEquals( $task1_id, $task2_id );
391-
392-
$hook_name = 'shepherd_' . tests_shepherd_get_hook_prefix() . '_task_already_scheduled';
393-
$this->assertSame( 0, did_action( $hook_name ) );
394-
395-
$this->assertTaskExecutesWithoutErrors( $task1_id );
396392
$this->assertTaskExecutesWithoutErrors( $task2_id );
397393

394+
$this->assertNotEquals( $task1_id, $task2_id );
395+
398396
$this->assertCount( 2, $spy );
399397
$this->assertEquals( 'https://api1.example.com/endpoint', $spy[0][0] );
400398
$this->assertEquals( 'https://api2.example.com/endpoint', $spy[1][0] );

0 commit comments

Comments
 (0)