Skip to content

Commit 6ff5c2c

Browse files
authored
Merge pull request #17 from stellarwp/feat/update-schema-to-v3
Update stellarwp/schema to v3
2 parents 46ea83e + ee90ee8 commit 6ff5c2c

File tree

15 files changed

+155
-1212
lines changed

15 files changed

+155
-1212
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
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.8] 2025-09-30
5+
## [0.0.8] 2025-10-02
66

7+
* Feature - Update the stellarwp/schema library to v3.
78
* Fix - Only delete task logs from the Task_Logs table when using DB_Logger in Provider::delete_tasks_on_action_deletion.
89
* Fix - Schedule cleanup task only when Shepherd tables have been registered successfully.
910
* Tweak - Update synchronous dispatch filter to default based on delay (true for no delay, false for delayed tasks).

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"require": {
3636
"php": ">=7.4",
3737
"stellarwp/db": "^1.1",
38-
"stellarwp/schema": "^2.0",
38+
"stellarwp/schema": "^3.1.2",
3939
"woocommerce/action-scheduler": "3.9.3",
4040
"psr/log": "^1.1"
4141
},

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ parameters:
2424
- %currentWorkingDirectory%/src
2525

2626
ignoreErrors:
27+
- '#Cannot assign new offset to.*Column_Collection#'
28+
- '#StellarWP\\Schema\\Collections\\Column_Collection does not accept StellarWP\\Schema\\Columns\\Contracts\\#'
2729
# Uses func_get_args()
2830
- '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#'
2931
# Uses func_get_args()

src/Abstracts/Model_Abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function delete(): void {
114114
*/
115115
public function to_array(): array {
116116
$table_interface = $this->get_table_interface();
117-
$columns = array_keys( $table_interface::get_columns() );
117+
$columns = $table_interface::get_columns()->get_names();
118118

119119
$model = [];
120120
foreach ( $columns as $column ) {

src/Abstracts/Table_Abstract.php

Lines changed: 0 additions & 233 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use StellarWP\DB\DB;
1616
use StellarWP\Shepherd\Config;
1717
use StellarWP\Shepherd\Tables\Utility\Safe_Dynamic_Prefix;
18-
use StellarWP\Shepherd\Traits\Custom_Table_Query_Methods;
19-
use DateTimeInterface;
2018

2119
/**
2220
* Class Table_Abstract
@@ -26,113 +24,6 @@
2624
* @package StellarWP\Shepherd\Abstracts
2725
*/
2826
abstract class Table_Abstract extends Table {
29-
use Custom_Table_Query_Methods;
30-
31-
/**
32-
* The PHP type for an integer.
33-
*
34-
* @since 0.0.1
35-
*
36-
* @var string
37-
*/
38-
public const PHP_TYPE_INT = 'int';
39-
40-
/**
41-
* The PHP type for a string.
42-
*
43-
* @since 0.0.1
44-
*
45-
* @var string
46-
*/
47-
public const PHP_TYPE_STRING = 'string';
48-
49-
/**
50-
* The PHP type for a float.
51-
*
52-
* @since 0.0.1
53-
*
54-
* @var string
55-
*/
56-
public const PHP_TYPE_FLOAT = 'float';
57-
58-
/**
59-
* The PHP type for a boolean.
60-
*
61-
* @since 0.0.1
62-
*
63-
* @var string
64-
*/
65-
public const PHP_TYPE_BOOL = 'bool';
66-
67-
/**
68-
* The PHP type for a datetime.
69-
*
70-
* @since 0.0.1
71-
*
72-
* @var string
73-
*/
74-
public const PHP_TYPE_DATETIME = DateTimeInterface::class;
75-
76-
/**
77-
* The column type for a bigint.
78-
*
79-
* @since 0.0.1
80-
*
81-
* @var string
82-
*/
83-
public const COLUMN_TYPE_BIGINT = 'bigint';
84-
85-
/**
86-
* The column type for a varchar.
87-
*
88-
* @since 0.0.1
89-
*
90-
* @var string
91-
*/
92-
public const COLUMN_TYPE_VARCHAR = 'varchar';
93-
94-
/**
95-
* The column type for a text.
96-
*
97-
* @since 0.0.1
98-
*
99-
* @var string
100-
*/
101-
public const COLUMN_TYPE_TEXT = 'text';
102-
103-
/**
104-
* The column type for a longtext.
105-
*
106-
* @since 0.0.1
107-
*
108-
* @var string
109-
*/
110-
public const COLUMN_TYPE_LONGTEXT = 'longtext';
111-
112-
/**
113-
* The column type for a timestamp.
114-
*
115-
* @since 0.0.1
116-
*
117-
* @var string
118-
*/
119-
public const COLUMN_TYPE_TIMESTAMP = 'timestamp';
120-
121-
public const SQL_RESERVED_DEFAULTS = [
122-
'CURRENT_TIMESTAMP',
123-
'CURRENT_DATE',
124-
'CURRENT_TIME',
125-
];
126-
127-
/**
128-
* The indexes for the table.
129-
*
130-
* @since 0.0.1
131-
*
132-
* @var array<array<string, string>>
133-
*/
134-
public const INDEXES = [];
135-
13627
/**
13728
* Constructor.
13829
*
@@ -174,130 +65,6 @@ public static function get_schema_slug(): string {
17465
return sprintf( static::$schema_slug, Config::get_hook_prefix() );
17566
}
17667

177-
/**
178-
* An array of all the columns in the table.
179-
*
180-
* @since 0.0.1
181-
*
182-
* @return array<string, array<string, string>>
183-
*/
184-
abstract public static function get_columns(): array;
185-
186-
/**
187-
* An array of all the columns that are searchable.
188-
*
189-
* @since 0.0.1
190-
*
191-
* @return string[]
192-
*/
193-
public static function get_searchable_columns(): array {
194-
return [];
195-
}
196-
197-
/**
198-
* Helper method to check and add an index to a table.
199-
*
200-
* @since 0.0.1
201-
*
202-
* @param array $results The results array to track changes.
203-
* @param string $index_name The name of the index.
204-
* @param string $columns The columns to index.
205-
*
206-
* @return array The updated results array.
207-
*/
208-
protected function check_and_add_index( array $results, string $index_name, string $columns ): array {
209-
$index_name = esc_sql( $index_name );
210-
211-
// Add index only if it does not exist.
212-
if ( $this->has_index( $index_name ) ) {
213-
return $results;
214-
}
215-
216-
$columns = esc_sql( $columns );
217-
218-
DB::query(
219-
DB::prepare( "ALTER TABLE %i ADD INDEX `{$index_name}` ( {$columns} )", esc_sql( static::table_name( true ) ) )
220-
);
221-
222-
return $results;
223-
}
224-
225-
/**
226-
* Returns the table creation SQL in the format supported
227-
* by the `dbDelta` function.
228-
*
229-
* @since 0.0.1
230-
* @since 0.0.3 Updated to remove an empty line after the columns and before the primary key.
231-
*
232-
* @return string The table creation SQL, in the format supported
233-
* by the `dbDelta` function.
234-
*/
235-
public function get_definition() {
236-
global $wpdb;
237-
$table_name = static::table_name( true );
238-
$charset_collate = $wpdb->get_charset_collate();
239-
$uid_column = static::uid_column();
240-
241-
$columns = static::get_columns();
242-
243-
$columns_definitions = [];
244-
foreach ( $columns as $column => $definition ) {
245-
$column_sql = "`{$column}` {$definition['type']}";
246-
247-
if ( ! empty( $definition['length'] ) ) {
248-
$column_sql .= "({$definition['length']})";
249-
}
250-
251-
if ( ! empty( $definition['unsigned'] ) ) {
252-
$column_sql .= ' UNSIGNED';
253-
}
254-
255-
$column_sql .= ! empty( $definition['nullable'] ) ? ' NULL' : ' NOT NULL';
256-
257-
if ( ! empty( $definition['auto_increment'] ) ) {
258-
$column_sql .= ' AUTO_INCREMENT';
259-
}
260-
261-
if ( ! empty( $definition['default'] ) ) {
262-
$column_sql .= ' DEFAULT ' . ( in_array( $definition['default'], self::SQL_RESERVED_DEFAULTS, true ) || in_array( $definition['php_type'], [ self::PHP_TYPE_INT, self::PHP_TYPE_BOOL, self::PHP_TYPE_FLOAT ], true ) ? $definition['default'] : "'{$definition['default']}'" );
263-
}
264-
265-
$columns_definitions[] = $column_sql;
266-
}
267-
268-
$columns_sql = implode( ',' . PHP_EOL, $columns_definitions );
269-
270-
return "
271-
CREATE TABLE `{$table_name}` (
272-
{$columns_sql},
273-
PRIMARY KEY (`{$uid_column}`)
274-
) {$charset_collate};
275-
";
276-
}
277-
278-
/**
279-
* Add indexes after table creation.
280-
*
281-
* @since 0.0.1
282-
*
283-
* @param array<string,string> $results A map of results in the format
284-
* returned by the `dbDelta` function.
285-
*
286-
* @return array<string,string> A map of results in the format returned by
287-
* the `dbDelta` function.
288-
*/
289-
protected function after_update( array $results ) {
290-
if ( empty( static::INDEXES ) || ! is_array( static::INDEXES ) ) {
291-
return $results;
292-
}
293-
294-
foreach ( static::INDEXES as $index ) {
295-
$this->check_and_add_index( $results, $index['name'], $index['columns'] );
296-
}
297-
298-
return $results;
299-
}
300-
30168
/**
30269
* Returns the base table name without the dynamic prefix.
30370
*

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static function get_container(): ContainerInterface {
8989
*/
9090
public static function get_hook_prefix(): string {
9191
if ( ! static::$hook_prefix ) {
92-
$class = __CLASS__;
92+
$class = self::class;
9393
throw new RuntimeException( "You must specify a hook prefix for your project with {$class}::set_hook_prefix()" );
9494
}
9595

src/Contracts/Model.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace StellarWP\Shepherd\Contracts;
1313

14-
use StellarWP\Shepherd\Abstracts\Table_Abstract;
14+
use StellarWP\Schema\Tables\Contracts\Table;
1515

1616
/**
1717
* The Shepherd model contract.
@@ -61,10 +61,11 @@ public function delete(): void;
6161
* Gets the table interface for the model.
6262
*
6363
* @since 0.0.1
64+
* @since 0.0.8 Updated to return Table instead.
6465
*
65-
* @return Table_Abstract The table interface.
66+
* @return Table The table interface.
6667
*/
67-
public function get_table_interface(): Table_Abstract;
68+
public function get_table_interface(): Table;
6869

6970
/**
7071
* Converts the model to an array.

src/Log.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use StellarWP\Shepherd\Contracts\Logger;
1919
use StellarWP\Shepherd\Abstracts\Model_Abstract;
2020
use DateTimeInterface;
21-
use StellarWP\Shepherd\Abstracts\Table_Abstract;
21+
use StellarWP\Schema\Tables\Contracts\Table;
2222
use Psr\Log\LogLevel;
2323
use InvalidArgumentException;
2424
use DateTime;
@@ -279,12 +279,13 @@ public function get_entry(): string {
279279
* Gets the table interface for the log.
280280
*
281281
* @since 0.0.1
282+
* @since 0.0.8 Updated to return Table instead.
282283
*
283-
* @return Table_Abstract The table interface.
284+
* @return Table The table interface.
284285
*
285286
* @throws RuntimeException If the log table interface is invalid.
286287
*/
287-
public function get_table_interface(): Table_Abstract {
288+
public function get_table_interface(): Table {
288289
$logger = Config::get_container()->get( Logger::class );
289290

290291
$table = null;
@@ -315,7 +316,7 @@ public function get_table_interface(): Table_Abstract {
315316
*/
316317
public function to_array(): array {
317318
$table_interface = Task_Logs_Table::class;
318-
$columns = array_keys( $table_interface::get_columns() );
319+
$columns = $table_interface::get_columns()->get_names();
319320

320321
$model = [];
321322
foreach ( $columns as $column ) {

0 commit comments

Comments
 (0)