From 6aa3161e0ad08bfd4bc89f10b83ba2c612dae4db Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 17:09:02 +0300 Subject: [PATCH 01/17] Update stellarwp/schema to v3 --- composer.json | 2 +- src/Abstracts/Table_Abstract.php | 311 ----------- src/Contracts/Model.php | 7 +- src/Log.php | 7 +- src/Tables/AS_Logs.php | 83 ++- src/Tables/Task_Logs.php | 114 +--- src/Tables/Tasks.php | 93 +--- src/Traits/Custom_Table_Query_Methods.php | 636 ---------------------- 8 files changed, 101 insertions(+), 1152 deletions(-) delete mode 100644 src/Abstracts/Table_Abstract.php delete mode 100644 src/Traits/Custom_Table_Query_Methods.php diff --git a/composer.json b/composer.json index 0bc50b46..afef8a85 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "require": { "php": ">=7.4", "stellarwp/db": "^1.1", - "stellarwp/schema": "^2.0", + "stellarwp/schema": "^3.1", "woocommerce/action-scheduler": "3.9.3", "psr/log": "^1.1" }, diff --git a/src/Abstracts/Table_Abstract.php b/src/Abstracts/Table_Abstract.php deleted file mode 100644 index 39a48f48..00000000 --- a/src/Abstracts/Table_Abstract.php +++ /dev/null @@ -1,311 +0,0 @@ -> - */ - public const INDEXES = []; - - /** - * Constructor. - * - * @since 0.0.1 - */ - public function __construct() { - $this->db = DB::class; - $this->container = Config::get_container(); - } - - /** - * Returns the base table name. - * - * This method is overridden to use the hook prefix. - * - * @since 0.0.1 - * - * @return string The base table name. - */ - public static function base_table_name(): string { - $container = Config::get_container(); - - return sprintf( - static::$base_table_name, - $container->get( Safe_Dynamic_Prefix::class )->get() - ); - } - - /** - * The schema slug. - * - * This method is overridden to use the hook prefix. - * - * @since 0.0.1 - * - * @return string The schema slug. - */ - public static function get_schema_slug(): string { - return sprintf( static::$schema_slug, Config::get_hook_prefix() ); - } - - /** - * An array of all the columns in the table. - * - * @since 0.0.1 - * - * @return array> - */ - abstract public static function get_columns(): array; - - /** - * An array of all the columns that are searchable. - * - * @since 0.0.1 - * - * @return string[] - */ - public static function get_searchable_columns(): array { - return []; - } - - /** - * Helper method to check and add an index to a table. - * - * @since 0.0.1 - * - * @param array $results The results array to track changes. - * @param string $index_name The name of the index. - * @param string $columns The columns to index. - * - * @return array The updated results array. - */ - protected function check_and_add_index( array $results, string $index_name, string $columns ): array { - $index_name = esc_sql( $index_name ); - - // Add index only if it does not exist. - if ( $this->has_index( $index_name ) ) { - return $results; - } - - $columns = esc_sql( $columns ); - - DB::query( - DB::prepare( "ALTER TABLE %i ADD INDEX `{$index_name}` ( {$columns} )", esc_sql( static::table_name( true ) ) ) - ); - - return $results; - } - - /** - * Returns the table creation SQL in the format supported - * by the `dbDelta` function. - * - * @since 0.0.1 - * @since 0.0.3 Updated to remove an empty line after the columns and before the primary key. - * - * @return string The table creation SQL, in the format supported - * by the `dbDelta` function. - */ - public function get_definition() { - global $wpdb; - $table_name = static::table_name( true ); - $charset_collate = $wpdb->get_charset_collate(); - $uid_column = static::uid_column(); - - $columns = static::get_columns(); - - $columns_definitions = []; - foreach ( $columns as $column => $definition ) { - $column_sql = "`{$column}` {$definition['type']}"; - - if ( ! empty( $definition['length'] ) ) { - $column_sql .= "({$definition['length']})"; - } - - if ( ! empty( $definition['unsigned'] ) ) { - $column_sql .= ' UNSIGNED'; - } - - $column_sql .= ! empty( $definition['nullable'] ) ? ' NULL' : ' NOT NULL'; - - if ( ! empty( $definition['auto_increment'] ) ) { - $column_sql .= ' AUTO_INCREMENT'; - } - - if ( ! empty( $definition['default'] ) ) { - $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']}'" ); - } - - $columns_definitions[] = $column_sql; - } - - $columns_sql = implode( ',' . PHP_EOL, $columns_definitions ); - - return " - CREATE TABLE `{$table_name}` ( - {$columns_sql}, - PRIMARY KEY (`{$uid_column}`) - ) {$charset_collate}; - "; - } - - /** - * Add indexes after table creation. - * - * @since 0.0.1 - * - * @param array $results A map of results in the format - * returned by the `dbDelta` function. - * - * @return array A map of results in the format returned by - * the `dbDelta` function. - */ - protected function after_update( array $results ) { - if ( empty( static::INDEXES ) || ! is_array( static::INDEXES ) ) { - return $results; - } - - foreach ( static::INDEXES as $index ) { - $this->check_and_add_index( $results, $index['name'], $index['columns'] ); - } - - return $results; - } - - /** - * Returns the base table name without the dynamic prefix. - * - * @since 0.0.1 - * - * @return string The base table name without the dynamic prefix. - */ - public static function raw_base_table_name(): string { - return static::$base_table_name; - } -} diff --git a/src/Contracts/Model.php b/src/Contracts/Model.php index 090c7e70..e117f582 100644 --- a/src/Contracts/Model.php +++ b/src/Contracts/Model.php @@ -11,7 +11,7 @@ namespace StellarWP\Shepherd\Contracts; -use StellarWP\Shepherd\Abstracts\Table_Abstract; +use StellarWP\Schema\Tables\Contracts\Table_Interface; /** * The Shepherd model contract. @@ -61,10 +61,11 @@ public function delete(): void; * Gets the table interface for the model. * * @since 0.0.1 + * @since 0.0.8 Updated to return Table_Interface instead. * - * @return Table_Abstract The table interface. + * @return Table_Interface The table interface. */ - public function get_table_interface(): Table_Abstract; + public function get_table_interface(): Table_Interface; /** * Converts the model to an array. diff --git a/src/Log.php b/src/Log.php index c3375e18..2d75eb52 100644 --- a/src/Log.php +++ b/src/Log.php @@ -18,7 +18,7 @@ use StellarWP\Shepherd\Contracts\Logger; use StellarWP\Shepherd\Abstracts\Model_Abstract; use DateTimeInterface; -use StellarWP\Shepherd\Abstracts\Table_Abstract; +use StellarWP\Schema\Tables\Contracts\Table_Interface; use Psr\Log\LogLevel; use InvalidArgumentException; use DateTime; @@ -279,12 +279,13 @@ public function get_entry(): string { * Gets the table interface for the log. * * @since 0.0.1 + * @since 0.0.8 Updated to return Table_Interface instead. * - * @return Table_Abstract The table interface. + * @return Table_Interface The table interface. * * @throws RuntimeException If the log table interface is invalid. */ - public function get_table_interface(): Table_Abstract { + public function get_table_interface(): Table_Interface { $logger = Config::get_container()->get( Logger::class ); $table = null; diff --git a/src/Tables/AS_Logs.php b/src/Tables/AS_Logs.php index d85cb9f4..78a1f773 100644 --- a/src/Tables/AS_Logs.php +++ b/src/Tables/AS_Logs.php @@ -9,11 +9,16 @@ namespace StellarWP\Shepherd\Tables; -use StellarWP\Shepherd\Abstracts\Table_Abstract as Table; +use StellarWP\Schema\Tables\Contracts\Table; use StellarWP\Shepherd\Log; use StellarWP\Shepherd\Config; -use StellarWP\DB\DB; use DateTime; +use StellarWP\Schema\Collections\Column_Collection; +use StellarWP\Schema\Columns\ID; +use StellarWP\Schema\Columns\Referenced_ID; +use StellarWP\Schema\Columns\String_Column; +use StellarWP\Schema\Columns\Datetime_Column; +use StellarWP\Schema\Tables\Table_Schema; /** * Action Scheduler logs table schema. @@ -21,6 +26,7 @@ * This is used only as an interface and should not be registered as a table for schema to handle. * * @since 0.0.1 + * @since 0.0.8 Updated to extend Table instead from the schema library. * * @package StellarWP\Shepherd\Tables; */ @@ -44,46 +50,35 @@ class AS_Logs extends Table { protected static $uid_column = 'log_id'; /** - * An array of all the columns in the table. + * The version number for this schema definition. * - * @since 0.0.1 + * @since 0.0.8 + * + * @var string + */ + const SCHEMA_VERSION = '0.0.1'; + + /** + * Gets the schema history for the table. * - * @return array> + * @since 0.0.8 + * + * @return array The schema history for the table. */ - public static function get_columns(): array { + public static function get_schema_history(): array { + $table_name = self::table_name( true ); + return [ - static::$uid_column => [ - 'type' => self::COLUMN_TYPE_BIGINT, - 'php_type' => self::PHP_TYPE_INT, - 'length' => 20, - 'unsigned' => true, - 'auto_increment' => true, - 'nullable' => false, - ], - 'action_id' => [ - 'type' => self::COLUMN_TYPE_BIGINT, - 'php_type' => self::PHP_TYPE_INT, - 'length' => 20, - 'unsigned' => true, - 'nullable' => false, - ], - 'message' => [ - 'type' => self::COLUMN_TYPE_TEXT, - 'php_type' => self::PHP_TYPE_STRING, - 'nullable' => false, - ], - 'log_date_gmt' => [ - 'type' => self::COLUMN_TYPE_TIMESTAMP, - 'php_type' => self::PHP_TYPE_DATETIME, - 'nullable' => true, - 'default' => '0000-00-00 00:00:00', - ], - 'log_date_local' => [ - 'type' => self::COLUMN_TYPE_TIMESTAMP, - 'php_type' => self::PHP_TYPE_DATETIME, - 'nullable' => true, - 'default' => '0000-00-00 00:00:00', - ], + self::SCHEMA_VERSION => function () use ( $table_name ) { + $columns = new Column_Collection(); + $columns[] = new ID( 'log_id' ); + $columns[] = new Referenced_ID( 'action_id' ); + $columns[] = new String_Column( 'message' ); + $columns[] = ( new Datetime_Column( 'log_date_gmt' ) )->set_nullable( true ); + $columns[] = ( new Datetime_Column( 'log_date_local' ) )->set_nullable( true ); + + return new Table_Schema( $table_name, $columns ); + }, ]; } @@ -91,18 +86,14 @@ public static function get_columns(): array { * Gets the logs by task ID. * * @since 0.0.1 + * @since 0.0.8 Updated to use the new get_all_by method. * * @param int $task_id The task ID. + * * @return Log[] The logs for the task. */ public static function get_by_task_id( int $task_id ): array { - $results = []; - - foreach ( self::fetch_all_where( DB::prepare( 'WHERE message LIKE %s', 'shepherd_' . Config::get_hook_prefix() . '||' . $task_id . '||%' ), 50, ARRAY_A, 'log_date_gmt ASC' ) as $log_array ) { - $results[] = self::get_model_from_array( $log_array ); - } - - return $results; + return self::get_all_by( 'message', 'shepherd_' . Config::get_hook_prefix() . '||' . $task_id . '||%', 'LIKE', 1000 ); } /** @@ -114,7 +105,7 @@ public static function get_by_task_id( int $task_id ): array { * * @return Log The log. */ - protected static function get_model_from_array( array $model_array ): Log { + public static function transform_from_array( array $model_array ): Log { $log = new Log(); $log->set_id( $model_array['log_id'] ); $log->set_action_id( $model_array['action_id'] ); diff --git a/src/Tables/Task_Logs.php b/src/Tables/Task_Logs.php index 8c109c5f..e07d5d14 100644 --- a/src/Tables/Task_Logs.php +++ b/src/Tables/Task_Logs.php @@ -9,45 +9,28 @@ namespace StellarWP\Shepherd\Tables; -use StellarWP\Shepherd\Abstracts\Table_Abstract as Table; +use StellarWP\Schema\Tables\Contracts\Table; use StellarWP\Shepherd\Log; use StellarWP\DB\DB; use DateTime; +use StellarWP\Schema\Columns\Created_At; +use StellarWP\Schema\Columns\ID; +use StellarWP\Schema\Columns\Referenced_ID; +use StellarWP\Schema\Columns\String_Column; +use StellarWP\Schema\Columns\Text_Column; +use StellarWP\Schema\Columns\Column_Types; +use StellarWP\Schema\Tables\Table_Schema; +use StellarWP\Schema\Collections\Column_Collection; /** * Task logs table schema. * * @since 0.0.1 + * @since 0.0.8 Updated to extend Table instead from the schema library. * * @package StellarWP\Shepherd\Tables; */ class Task_Logs extends Table { - /** - * The indexes for the table. - * - * @since 0.0.1 - * - * @var array> - */ - public const INDEXES = [ - [ - 'name' => 'task_id', - 'columns' => 'task_id', - ], - [ - 'name' => 'action_id', - 'columns' => 'action_id', - ], - [ - 'name' => 'type', - 'columns' => 'type', - ], - [ - 'name' => 'level', - 'columns' => 'level', - ], - ]; - /** * The schema version. * @@ -95,59 +78,27 @@ class Task_Logs extends Table { protected static $uid_column = 'id'; /** - * An array of all the columns in the table. + * Gets the schema history for the table. * - * @since 0.0.1 + * @since 0.0.8 * - * @return array> + * @return array The schema history for the table. */ - public static function get_columns(): array { + public static function get_schema_history(): array { + $table_name = self::table_name( true ); return [ - static::$uid_column => [ - 'type' => self::COLUMN_TYPE_BIGINT, - 'php_type' => self::PHP_TYPE_INT, - 'length' => 20, - 'unsigned' => true, - 'auto_increment' => true, - 'nullable' => false, - ], - 'task_id' => [ - 'type' => self::COLUMN_TYPE_BIGINT, - 'php_type' => self::PHP_TYPE_INT, - 'length' => 20, - 'unsigned' => true, - 'nullable' => false, - ], - 'action_id' => [ - 'type' => self::COLUMN_TYPE_BIGINT, - 'php_type' => self::PHP_TYPE_INT, - 'length' => 20, - 'unsigned' => true, - 'nullable' => false, - ], - 'date' => [ - 'type' => self::COLUMN_TYPE_TIMESTAMP, - 'php_type' => self::PHP_TYPE_DATETIME, - 'nullable' => false, - 'default' => 'CURRENT_TIMESTAMP', - ], - 'level' => [ - 'type' => self::COLUMN_TYPE_VARCHAR, - 'php_type' => self::PHP_TYPE_STRING, - 'length' => 191, - 'nullable' => false, - ], - 'type' => [ - 'type' => self::COLUMN_TYPE_VARCHAR, - 'php_type' => self::PHP_TYPE_STRING, - 'length' => 191, - 'nullable' => false, - ], - 'entry' => [ - 'type' => self::COLUMN_TYPE_LONGTEXT, - 'php_type' => self::PHP_TYPE_STRING, - 'nullable' => false, - ], + self::SCHEMA_VERSION => function () use ( $table_name ) { + $columns = new Column_Collection(); + $columns[] = new ID( 'id' ); + $columns[] = new Referenced_ID( 'task_id' ); + $columns[] = new Referenced_ID( 'action_id' ); + $columns[] = new Created_At( 'date' ); + $columns[] = ( new String_Column( 'level' ) )->set_length( 191 )->set_is_index( true ); + $columns[] = ( new String_Column( 'type' ) )->set_length( 191 )->set_is_index( true ); + $columns[] = ( new Text_Column( 'entry' ) )->set_type( Column_Types::LONGTEXT ); + + return new Table_Schema( $table_name, $columns ); + }, ]; } @@ -155,18 +106,13 @@ public static function get_columns(): array { * Gets the logs by task ID. * * @since 0.0.1 + * @since 0.0.8 Updated to use the new get_all_by method. * * @param int $task_id The task ID. * @return Log[] The logs for the task. */ public static function get_by_task_id( int $task_id ): array { - $results = []; - - foreach ( self::fetch_all_where( DB::prepare( 'WHERE task_id = %d', $task_id ), 50, ARRAY_A, 'date ASC' ) as $log_array ) { - $results[] = self::get_model_from_array( $log_array ); - } - - return $results; + return self::get_all_by( 'task_id', $task_id, '=', 1000, 'date ASC' ); } /** @@ -178,7 +124,7 @@ public static function get_by_task_id( int $task_id ): array { * * @return Log The log. */ - protected static function get_model_from_array( array $model_array ): Log { + public static function transform_from_array( array $model_array ): Log { $log = new Log(); $log->set_id( $model_array['id'] ); $log->set_task_id( $model_array['task_id'] ); diff --git a/src/Tables/Tasks.php b/src/Tables/Tasks.php index a6498ae6..bdd8e4cd 100644 --- a/src/Tables/Tasks.php +++ b/src/Tables/Tasks.php @@ -9,40 +9,26 @@ namespace StellarWP\Shepherd\Tables; -use StellarWP\Shepherd\Abstracts\Table_Abstract as Table; +use StellarWP\Schema\Tables\Contracts\Table; use StellarWP\Shepherd\Contracts\Task; +use StellarWP\Schema\Collections\Column_Collection; +use StellarWP\Schema\Columns\ID; +use StellarWP\Schema\Columns\Referenced_ID; +use StellarWP\Schema\Columns\String_Column; +use StellarWP\Schema\Columns\Text_Column; +use StellarWP\Schema\Columns\Integer_Column; +use StellarWP\Schema\Tables\Table_Schema; use InvalidArgumentException; /** * Tasks table schema. * * @since 0.0.1 + * @since 0.0.8 Updated to extend Table instead from the schema library. * * @package StellarWP\Shepherd\Tables; */ class Tasks extends Table { - /** - * The indexes for the table. - * - * @since 0.0.1 - * - * @var array> - */ - public const INDEXES = [ - [ - 'name' => 'action_id', - 'columns' => 'action_id', - ], - [ - 'name' => 'args_hash', - 'columns' => 'args_hash', - ], - [ - 'name' => 'class_hash', - 'columns' => 'class_hash', - ], - ]; - /** * The schema version. * @@ -91,54 +77,25 @@ class Tasks extends Table { protected static $uid_column = 'id'; /** - * An array of all the columns in the table. + * Gets the schema history for the table. * - * @since 0.0.1 + * @since 0.0.8 * - * @return array> + * @return array The schema history for the table. */ - public static function get_columns(): array { + public static function get_schema_history(): array { + $table_name = self::table_name( true ); return [ - static::$uid_column => [ - 'type' => self::COLUMN_TYPE_BIGINT, - 'php_type' => self::PHP_TYPE_INT, - 'length' => 20, - 'unsigned' => true, - 'auto_increment' => true, - 'nullable' => false, - ], - 'action_id' => [ - 'type' => self::COLUMN_TYPE_BIGINT, - 'php_type' => self::PHP_TYPE_INT, - 'length' => 20, - 'unsigned' => true, - 'nullable' => false, - ], - 'class_hash' => [ - 'type' => self::COLUMN_TYPE_VARCHAR, - 'php_type' => self::PHP_TYPE_STRING, - 'length' => 191, - 'nullable' => false, - ], - 'args_hash' => [ - 'type' => self::COLUMN_TYPE_VARCHAR, - 'php_type' => self::PHP_TYPE_STRING, - 'length' => 191, - 'nullable' => false, - ], - 'data' => [ - 'type' => self::COLUMN_TYPE_LONGTEXT, - 'php_type' => self::PHP_TYPE_STRING, - 'nullable' => true, - ], - 'current_try' => [ - 'type' => self::COLUMN_TYPE_BIGINT, - 'php_type' => self::PHP_TYPE_INT, - 'length' => 20, - 'unsigned' => true, - 'nullable' => false, - 'default' => 0, - ], + self::SCHEMA_VERSION => function () use ( $table_name ) { + $columns = new Column_Collection(); + $columns[] = new ID( 'id' ); + $columns[] = new Referenced_ID( 'action_id' ); + $columns[] = ( new String_Column( 'class_hash' ) )->set_length( 191 )->set_is_index( true ); + $columns[] = ( new String_Column( 'args_hash' ) )->set_length( 191 )->set_is_index( true ); + $columns[] = ( new Text_Column( 'data' ) )->set_nullable( true ); + $columns[] = ( new Integer_Column( 'current_try' ) )->set_length( 20 )->set_signed( false )->set_default( 0 ); + return new Table_Schema( $table_name, $columns ); + }, ]; } @@ -183,7 +140,7 @@ public static function get_by_args_hash( string $args_hash ): array { * * @throws InvalidArgumentException If the task class does not exist or does not implement the Task interface. */ - protected static function get_model_from_array( array $task_array ): Task { + public static function transform_from_array( array $task_array ): Task { $task_data = json_decode( $task_array['data'] ?? '[]', true ); $task_class = $task_data['task_class'] ?? ''; diff --git a/src/Traits/Custom_Table_Query_Methods.php b/src/Traits/Custom_Table_Query_Methods.php deleted file mode 100644 index f7329cce..00000000 --- a/src/Traits/Custom_Table_Query_Methods.php +++ /dev/null @@ -1,636 +0,0 @@ -> The rows from the table. - */ - public static function fetch_all( int $batch_size = 50, string $output = OBJECT, string $where_clause = '', string $order_by = '' ): Generator { - $fetched = 0; - $total = null; - $offset = 0; - - do { - // On first iteration, we need to set the SQL_CALC_FOUND_ROWS flag. - $sql_calc_found_rows = 0 === $fetched ? 'SQL_CALC_FOUND_ROWS' : ''; - - $uid_column = static::uid_column(); - - $order_by = $order_by ?: $uid_column . ' ASC'; - - $query = DB::prepare( - "SELECT {$sql_calc_found_rows} * FROM %i {$where_clause} ORDER BY {$order_by} LIMIT %d, %d", - static::table_name( true ), - $offset, - $batch_size - ); - - $batch = DB::get_results( - $query, - $output - ); - - // We need to get the total number of rows, only after the first batch. - $total ??= DB::get_var( 'SELECT FOUND_ROWS()' ); - $fetched += count( $batch ); - - $offset += $batch_size; - - yield from $batch; - } while ( $fetched < $total ); - } - - /** - * Inserts a single row into the table. - * - * @since 0.0.1 - * - * @param array $entry The entry to insert. - * - * @return bool|int The number of rows affected, or `false` on failure. - */ - public static function insert( array $entry ) { - return static::insert_many( [ $entry ] ); - } - - /** - * Updates a single row in the table. - * - * @since 0.0.1 - * - * @param array $entry The entry to update. - * - * @return bool Whether the update was successful. - */ - public static function update_single( array $entry ): bool { - return static::update_many( [ $entry ] ); - } - - /** - * Inserts or updates a single row in the table. - * - * @since 0.0.1 - * - * @param array $entry The entry to upsert. - * - * @return bool Whether the upsert was successful. - */ - public static function upsert( array $entry ): bool { - $uid_column = static::uid_column(); - $uid = $entry[ $uid_column ] ?? false; - - return $uid ? static::update_single( $entry ) : static::insert( $entry ); - } - - /** - * Inserts multiple rows into the table. - * - * @since 0.0.1 - * - * @param array $entries The entries to insert. - * - * @return bool|int The number of rows affected, or `false` on failure. - */ - public static function insert_many( array $entries ) { - [ $prepared_columns, $prepared_values ] = static::prepare_statements_values( $entries ); - - return DB::query( - DB::prepare( - "INSERT INTO %i ({$prepared_columns}) VALUES {$prepared_values}", - static::table_name( true ), - ) - ); - } - - /** - * Updates multiple rows into the table. - * - * @since 0.0.1 - * - * @param array $entries The entries to update. - * - * @return bool Whether the update was successful. - */ - public static function update_many( array $entries ): bool { - $uid_column = static::uid_column(); - - $queries = []; - $columns = array_keys( static::get_columns() ); - foreach ( $entries as $entry ) { - $uid = $entry[ $uid_column ] ?? ''; - - if ( ! $uid ) { - continue; - } - - $set_statement = []; - - foreach ( $entry as $column => $value ) { - if ( $column === $uid_column ) { - continue; - } - - if ( ! in_array( $column, $columns, true ) ) { - continue; - } - - if ( $value instanceof DateTimeInterface ) { - $value = $value->format( 'Y-m-d H:i:s' ); - } - - $set_statement[] = DB::prepare( "`{$column}` = %s", $value ); - } - - $set_statement = implode( ', ', $set_statement ); - - $queries[] = DB::prepare( - "UPDATE %i SET {$set_statement} WHERE {$uid_column} = %s;", - static::table_name( true ), - $uid - ); - } - - return (bool) DB::query( implode( '', $queries ) ); - } - - /** - * Deletes a single row from the table. - * - * @since 0.0.1 - * - * @param int $uid The ID of the row to delete. - * @param string $column The column to use for the delete query. - * - * @return bool Whether the delete was successful. - */ - public static function delete( int $uid, string $column = '' ): bool { - return static::delete_many( [ $uid ], $column ); - } - - /** - * Deletes multiple rows from the table. - * - * @since 0.0.1 - * - * @param array $ids The IDs of the rows to delete. - * @param string $column The column to use for the delete query. - * - * @return bool|int The number of rows affected, or `false` on failure. - */ - public static function delete_many( array $ids, string $column = '' ) { - $ids = array_filter( - array_map( - fn( $id ) => is_numeric( $id ) ? (int) $id : "'{$id}'", - $ids - ) - ); - - if ( empty( $ids ) ) { - return false; - } - - $prepared_ids = implode( ', ', $ids ); - - $column = $column ?: static::uid_column(); - - return DB::query( - DB::prepare( - "DELETE FROM %i WHERE {$column} IN ({$prepared_ids})", - static::table_name( true ), - ) - ); - } - /** - * Prepares the statements and values for the insert and update queries. - * - * @since 0.0.1 - * - * @param array $entries The entries to prepare. - * - * @return array The prepared statements and values. - */ - protected static function prepare_statements_values( array $entries ): array { - $columns = array_keys( $entries[0] ); - $prepared_columns = implode( - ', ', - array_map( - static fn( string $column ) => "`$column`", - $columns - ) - ); - $prepared_values = implode( - ', ', - array_map( - static fn ( array $entry ) => '(' . implode( ', ', array_map( static fn( $e ) => DB::prepare( '%s', $e instanceof DateTimeInterface ? $e->format( 'Y-m-d H:i:s' ) : $e ), $entry ) ) . ')', - $entries - ) - ); - - return [ $prepared_columns, $prepared_values ]; - } - - /** - * Fetches all the rows from the table using a batched query and a WHERE clause. - * - * @since 0.0.1 - * - * @param string $where_clause The WHERE clause to use. - * @param int $batch_size The number of rows to fetch per batch. - * @param string $output The output type of the query, one of OBJECT, ARRAY_A, or ARRAY_N. - * @param string $order_by The optional ORDER BY clause to use. - * - * @return Generator> The rows from the table. - */ - public static function fetch_all_where( string $where_clause, int $batch_size = 50, string $output = OBJECT, string $order_by = '' ): Generator { - return static::fetch_all( $batch_size, $output, $where_clause, $order_by ); - } - - /** - * Fetches the first row from the table using a WHERE clause. - * - * @since 0.0.1 - * - * @param string $where_clause The prepared WHERE clause to use. - * @param string $output The output type of the query, one of OBJECT, ARRAY_A, or ARRAY_N. - * - * @return array|object|null The row from the table, or `null` if no row was found. - */ - public static function fetch_first_where( string $where_clause, string $output = OBJECT ) { - return DB::get_row( - DB::prepare( - "SELECT * FROM %i {$where_clause} LIMIT 1", - static::table_name( true ) - ), - $output - ); - } - - /** - * Method used to paginate the results of a query. - * - * Also supports joining another table. - * - * @since 0.0.1 - * - * @param array $args The query arguments. - * @param int $per_page The number of items to display per page. - * @param int $page The current page number. - * @param string $join_table The table to join. - * @param string $join_condition The condition to join on. - * @param array $selectable_joined_columns The columns from the joined table to select. - * @param string $output The output type of the query, one of OBJECT, ARRAY_A, or ARRAY_N. - * - * @return array The items. - * @throws InvalidArgumentException If the table to join is the same as the current table. - * If the join condition does not contain an equal sign. - * If the join condition does not contain valid columns. - */ - public static function paginate( array $args, int $per_page = 20, int $page = 1, string $join_table = '', string $join_condition = '', array $selectable_joined_columns = [], string $output = OBJECT ): array { - $is_join = (bool) $join_table; - - if ( $is_join && static::table_name( true ) === $join_table::table_name( true ) ) { - throw new InvalidArgumentException( 'The table to join must be different from the current table.' ); - } - - $per_page = min( max( 1, $per_page ), 200 ); - $page = max( 1, $page ); - - $offset = ( $page - 1 ) * $per_page; - - $orderby = $args['orderby'] ?? static::uid_column(); - $order = strtoupper( $args['order'] ?? 'ASC' ); - - if ( ! in_array( $orderby, array_keys( static::get_columns() ), true ) ) { - $orderby = static::uid_column(); - } - - if ( ! in_array( $order, [ 'ASC', 'DESC' ], true ) ) { - $order = 'ASC'; - } - - $where = static::build_where_from_args( $args ); - - [ $join, $secondary_columns ] = $is_join ? static::get_join_parts( $join_table, $join_condition, $selectable_joined_columns ) : [ '', '' ]; - - return DB::get_results( - DB::prepare( - "SELECT a.*{$secondary_columns} FROM %i a {$join} {$where} ORDER BY a.{$orderby} {$order} LIMIT %d, %d", - static::table_name( true ), - $offset, - $per_page - ), - $output - ); - } - - /** - * Gets the total number of items in the table. - * - * @since 0.0.1 - * - * @param array $args The query arguments. - * - * @return int The total number of items in the table. - */ - public static function get_total_items( array $args = [] ): int { - $where = static::build_where_from_args( $args ); - - return (int) DB::get_var( - DB::prepare( - "SELECT COUNT(*) FROM %i a {$where}", - static::table_name( true ) - ) - ); - } - - /** - * Builds a WHERE clause from the provided arguments. - * - * @since 0.0.1 - * - * @param array $args The query arguments. - * - * @return string The WHERE clause. - */ - protected static function build_where_from_args( array $args = [] ): string { - $query_operator = strtoupper( $args['query_operator'] ?? 'AND' ); - - if ( ! in_array( $query_operator, [ 'AND', 'OR' ], true ) ) { - $query_operator = 'AND'; - } - - unset( $args['order'], $args['orderby'], $args['query_operator'] ); - - if ( empty( $args ) ) { - return ''; - } - - $joined_prefix = 'a.'; - - $where = []; - - $search = $args['term'] ?? ''; - if ( $search ) { - $searchable_columns = static::get_searchable_columns(); - - if ( ! empty( $searchable_columns ) ) { - $search_where = []; - - foreach ( $searchable_columns as $column ) { - $search_where[] = DB::prepare( "{$joined_prefix}{$column} LIKE %s", '%' . DB::esc_like( $search ) . '%' ); - } - - $where[] = '(' . implode( ' OR ', $search_where ) . ')'; - } - } - - $columns = array_keys( static::get_columns() ); - - foreach ( $args as $arg ) { - if ( ! is_array( $arg ) ) { - continue; - } - - if ( empty( $arg['column'] ) ) { - continue; - } - - if ( ! in_array( $arg['column'], $columns, true ) ) { - continue; - } - - if ( empty( $arg['value'] ) ) { - // We check that the column has any value then. - $arg['value'] = ''; - $arg['operator'] = '!='; - } - - if ( empty( $arg['operator'] ) ) { - $arg['operator'] = '='; - } - - // For anything else, you should build your own query! - if ( ! in_array( $arg['operator'], [ '=', '!=', '>', '<', '>=', '<=' ], true ) ) { - $arg['operator'] = '='; - } - - $column = $arg['column']; - $operator = $arg['operator']; - $value = $arg['value']; - $placeholder = is_numeric( $value ) ? '%d' : '%s'; // Only integers and strings are supported currently. - - $where[] = DB::prepare( "{$joined_prefix}{$column} {$operator} {$placeholder}", $value ); - } - - if ( empty( $where ) ) { - return ''; - } - - return 'WHERE ' . implode( " {$query_operator} ", $where ); - } - - /** - * Gets the JOIN parts of the query. - * - * @since 0.0.1 - * - * @param string $join_table The table to join. - * @param string $join_condition The condition to join on. - * @param array $selectable_joined_columns The columns from the joined table to select. - * - * @return array The JOIN statement and the secondary columns to select. - * @throws InvalidArgumentException If the join condition does not contain an equal sign. - * If the join condition does not contain valid columns. - */ - protected static function get_join_parts( string $join_table, string $join_condition, array $selectable_joined_columns = [] ): array { - if ( ! strstr( $join_condition, '=' ) ) { - throw new InvalidArgumentException( 'The join condition must contain an equal sign.' ); - } - - $join_condition = array_map( 'trim', explode( '=', $join_condition, 2 ) ); - - $secondary_table_columns = array_keys( $join_table::get_columns() ); - - $both_table_columns = array_merge( array_keys( static::get_columns() ), $secondary_table_columns ); - - if ( ! in_array( $join_condition[0], $both_table_columns, true ) || ! in_array( $join_condition[1], $both_table_columns, true ) ) { - throw new InvalidArgumentException( 'The join condition must contain valid columns.' ); - } - - $join_condition = 'a.' . str_replace( [ 'a.', 'b.' ], '', $join_condition[0] ) . ' = b.' . str_replace( [ 'a.', 'b.' ], '', $join_condition[1] ); - - $clean_secondary_columns = []; - - foreach ( array_map( 'trim', $selectable_joined_columns ) as $column ) { - if ( ! in_array( $column, $secondary_table_columns, true ) ) { - continue; - } - - $clean_secondary_columns[] = 'b.' . $column; - } - - $clean_secondary_columns = $clean_secondary_columns ? ', ' . implode( ', ', $clean_secondary_columns ) : ''; - - return [ - DB::prepare( "JOIN %i b ON {$join_condition}", $join_table::table_name( true ) ), - $clean_secondary_columns, - ]; - } - - /** - * Gets all models by a column. - * - * @since 0.0.1 - * - * @param string $column The column to get the models by. - * @param mixed $value The value to get the models by. - * @param int $limit The limit of models to return. - * - * @return Model[] The models, or an empty array if no models are found. - * - * @throws InvalidArgumentException If the column does not exist. - */ - public static function get_all_by( string $column, $value, int $limit = 50 ): ?array { - [ $value, $placeholder ] = self::prepare_value_for_query( $column, $value ); - - $results = []; - foreach ( static::fetch_all_where( DB::prepare( "WHERE {$column} = {$placeholder}", $value ), $limit, ARRAY_A ) as $task_array ) { - if ( empty( $task_array[ static::uid_column() ] ) ) { - continue; - } - - $results[] = static::get_model_from_array( $task_array ); - } - - return $results; - } - - /** - * Gets the first model by a column. - * - * @since 0.0.1 - * - * @param string $column The column to get the model by. - * @param mixed $value The value to get the model by. - * - * @return ?Model The model, or `null` if no model is found. - * - * @throws InvalidArgumentException If the column does not exist. - */ - public static function get_first_by( string $column, $value ): ?Model { - [ $value, $placeholder ] = self::prepare_value_for_query( $column, $value ); - - $task_array = static::fetch_first_where( DB::prepare( "WHERE {$column} = {$placeholder}", $value ), ARRAY_A ); - - if ( empty( $task_array[ static::uid_column() ] ) ) { - return null; - } - - return static::get_model_from_array( $task_array ); - } - - /** - * Prepares a value for a query. - * - * @since 0.0.1 - * - * @param string $column The column to prepare the value for. - * @param mixed $value The value to prepare. - * - * @return array The prepared value and placeholder. - * - * @throws InvalidArgumentException If the column does not exist. - */ - private static function prepare_value_for_query( string $column, $value ): array { - $columns = static::get_columns(); - - if ( ! isset( $columns[ $column ] ) ) { - throw new InvalidArgumentException( "Column $column does not exist." ); - } - - $column_type = $columns[ $column ]['php_type']; - - switch ( $column_type ) { - case Table::PHP_TYPE_INT: - case Table::PHP_TYPE_BOOL: - $value = (int) $value; - $placeholder = '%d'; - break; - case Table::PHP_TYPE_STRING: - case Table::PHP_TYPE_DATETIME: - $value = $value instanceof DateTimeInterface ? $value->format( 'Y-m-d H:i:s' ) : (string) $value; - $placeholder = '%s'; - break; - case Table::PHP_TYPE_FLOAT: - $value = (float) $value; - $placeholder = '%f'; - break; - default: - throw new InvalidArgumentException( "Unsupported column type: $column_type." ); - } - - return [ $value, $placeholder ]; - } - - /** - * Gets a model by its ID. - * - * @since 0.0.1 - * - * @param int $id The ID. - * - * @return ?Model The model, or null if not found. - * - * @throws InvalidArgumentException If the model class does not implement the Model interface. - */ - public static function get_by_id( int $id ): ?Model { - return static::get_first_by( static::uid_column(), $id ); - } - - // phpcs:disable Squiz.Commenting.FunctionComment.InvalidNoReturn, Generic.CodeAnalysis.UnusedFunctionParameter.Found - - /** - * Gets a model from an array. - * - * @since 0.0.1 - * - * @param array $model_array The model array. - * - * @return Model The model. - */ - abstract protected static function get_model_from_array( array $model_array ): Model; - - // phpcs:enable Squiz.Commenting.FunctionComment.InvalidNoReturn, Generic.CodeAnalysis.UnusedFunctionParameter.Found -} From 3538c276422e2f37ff274ff487c68cc6a9f280be Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 1 Oct 2025 14:09:53 +0000 Subject: [PATCH 02/17] chore: autopublish 2025-10-01T14:09:53Z --- src/Tables/Task_Logs.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Tables/Task_Logs.php b/src/Tables/Task_Logs.php index e07d5d14..07b4ce50 100644 --- a/src/Tables/Task_Logs.php +++ b/src/Tables/Task_Logs.php @@ -11,7 +11,6 @@ use StellarWP\Schema\Tables\Contracts\Table; use StellarWP\Shepherd\Log; -use StellarWP\DB\DB; use DateTime; use StellarWP\Schema\Columns\Created_At; use StellarWP\Schema\Columns\ID; From 54d158c754ca56d3951683a83be35cd56d0e3536 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 17:10:57 +0300 Subject: [PATCH 03/17] Added changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27d1614d..1863105c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard. -## [0.0.8] 2025-09-30 +## [0.0.8] 2025-10-01 +* Feature - Update the stellarwp/schema library to v3. * Fix - Only delete task logs from the Task_Logs table when using DB_Logger in Provider::delete_tasks_on_action_deletion. * Fix - Schedule cleanup task only when Shepherd tables have been registered successfully. * Tweak - Update synchronous dispatch filter to default based on delay (true for no delay, false for delayed tasks). From 368a846cc97ae3bad2f07050d729eda3e4dc684b Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 17:17:49 +0300 Subject: [PATCH 04/17] Updated table contract --- src/Abstracts/Table_Abstract.php | 78 ++++++++++++++++++++++++++++++++ src/Tables/AS_Logs.php | 6 +-- src/Tables/Task_Logs.php | 6 +-- src/Tables/Tasks.php | 6 +-- 4 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 src/Abstracts/Table_Abstract.php diff --git a/src/Abstracts/Table_Abstract.php b/src/Abstracts/Table_Abstract.php new file mode 100644 index 00000000..c558a13c --- /dev/null +++ b/src/Abstracts/Table_Abstract.php @@ -0,0 +1,78 @@ +db = DB::class; + $this->container = Config::get_container(); + } + + /** + * Returns the base table name. + * + * This method is overridden to use the hook prefix. + * + * @since 0.0.1 + * + * @return string The base table name. + */ + public static function base_table_name(): string { + $container = Config::get_container(); + + return sprintf( + static::$base_table_name, + $container->get( Safe_Dynamic_Prefix::class )->get() + ); + } + + /** + * The schema slug. + * + * This method is overridden to use the hook prefix. + * + * @since 0.0.1 + * + * @return string The schema slug. + */ + public static function get_schema_slug(): string { + return sprintf( static::$schema_slug, Config::get_hook_prefix() ); + } + + /** + * Returns the base table name without the dynamic prefix. + * + * @since 0.0.1 + * + * @return string The base table name without the dynamic prefix. + */ + public static function raw_base_table_name(): string { + return static::$base_table_name; + } +} diff --git a/src/Tables/AS_Logs.php b/src/Tables/AS_Logs.php index 78a1f773..d860c20a 100644 --- a/src/Tables/AS_Logs.php +++ b/src/Tables/AS_Logs.php @@ -9,7 +9,7 @@ namespace StellarWP\Shepherd\Tables; -use StellarWP\Schema\Tables\Contracts\Table; +use StellarWP\Shepherd\Abstracts\Table_Abstract; use StellarWP\Shepherd\Log; use StellarWP\Shepherd\Config; use DateTime; @@ -26,11 +26,11 @@ * This is used only as an interface and should not be registered as a table for schema to handle. * * @since 0.0.1 - * @since 0.0.8 Updated to extend Table instead from the schema library. + * @since 0.0.8 Updated to be compatible with the updated contract. * * @package StellarWP\Shepherd\Tables; */ -class AS_Logs extends Table { +class AS_Logs extends Table_Abstract { /** * The base table name, without the table prefix. * diff --git a/src/Tables/Task_Logs.php b/src/Tables/Task_Logs.php index 07b4ce50..18523e6a 100644 --- a/src/Tables/Task_Logs.php +++ b/src/Tables/Task_Logs.php @@ -9,7 +9,7 @@ namespace StellarWP\Shepherd\Tables; -use StellarWP\Schema\Tables\Contracts\Table; +use StellarWP\Shepherd\Abstracts\Table_Abstract; use StellarWP\Shepherd\Log; use DateTime; use StellarWP\Schema\Columns\Created_At; @@ -25,11 +25,11 @@ * Task logs table schema. * * @since 0.0.1 - * @since 0.0.8 Updated to extend Table instead from the schema library. + * @since 0.0.8 Updated to be compatible with the updated contract. * * @package StellarWP\Shepherd\Tables; */ -class Task_Logs extends Table { +class Task_Logs extends Table_Abstract { /** * The schema version. * diff --git a/src/Tables/Tasks.php b/src/Tables/Tasks.php index bdd8e4cd..6485267b 100644 --- a/src/Tables/Tasks.php +++ b/src/Tables/Tasks.php @@ -9,7 +9,7 @@ namespace StellarWP\Shepherd\Tables; -use StellarWP\Schema\Tables\Contracts\Table; +use StellarWP\Shepherd\Abstracts\Table_Abstract; use StellarWP\Shepherd\Contracts\Task; use StellarWP\Schema\Collections\Column_Collection; use StellarWP\Schema\Columns\ID; @@ -24,11 +24,11 @@ * Tasks table schema. * * @since 0.0.1 - * @since 0.0.8 Updated to extend Table instead from the schema library. + * @since 0.0.8 Updated to be compatible with the updated contract. * * @package StellarWP\Shepherd\Tables; */ -class Tasks extends Table { +class Tasks extends Table_Abstract { /** * The schema version. * From de1cec069232fa52c3701db1815c5212e67d29f1 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 17:21:05 +0300 Subject: [PATCH 05/17] Updated contact usage --- src/Contracts/Model.php | 8 ++++---- src/Log.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Contracts/Model.php b/src/Contracts/Model.php index e117f582..41694c24 100644 --- a/src/Contracts/Model.php +++ b/src/Contracts/Model.php @@ -11,7 +11,7 @@ namespace StellarWP\Shepherd\Contracts; -use StellarWP\Schema\Tables\Contracts\Table_Interface; +use StellarWP\Schema\Tables\Contracts\Table; /** * The Shepherd model contract. @@ -61,11 +61,11 @@ public function delete(): void; * Gets the table interface for the model. * * @since 0.0.1 - * @since 0.0.8 Updated to return Table_Interface instead. + * @since 0.0.8 Updated to return Table instead. * - * @return Table_Interface The table interface. + * @return Table The table interface. */ - public function get_table_interface(): Table_Interface; + public function get_table_interface(): Table; /** * Converts the model to an array. diff --git a/src/Log.php b/src/Log.php index 2d75eb52..7807da8d 100644 --- a/src/Log.php +++ b/src/Log.php @@ -18,7 +18,7 @@ use StellarWP\Shepherd\Contracts\Logger; use StellarWP\Shepherd\Abstracts\Model_Abstract; use DateTimeInterface; -use StellarWP\Schema\Tables\Contracts\Table_Interface; +use StellarWP\Schema\Tables\Contracts\Table; use Psr\Log\LogLevel; use InvalidArgumentException; use DateTime; @@ -279,13 +279,13 @@ public function get_entry(): string { * Gets the table interface for the log. * * @since 0.0.1 - * @since 0.0.8 Updated to return Table_Interface instead. + * @since 0.0.8 Updated to return Table instead. * - * @return Table_Interface The table interface. + * @return Table The table interface. * * @throws RuntimeException If the log table interface is invalid. */ - public function get_table_interface(): Table_Interface { + public function get_table_interface(): Table { $logger = Config::get_container()->get( Logger::class ); $table = null; From ad00042039f0030fa3bbe848e7b6a2809d74b03b Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 17:26:58 +0300 Subject: [PATCH 06/17] Update test data --- .../wpunit/Abstracts/Table_Abstract_Test.php | 21 +++++++++++++++---- tests/wpunit/Contracts/Task_Test.php | 2 +- .../Custom_Table_Query_Methods_Test.php | 19 ++++++++++++----- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/wpunit/Abstracts/Table_Abstract_Test.php b/tests/wpunit/Abstracts/Table_Abstract_Test.php index 03d11f82..9adfed58 100644 --- a/tests/wpunit/Abstracts/Table_Abstract_Test.php +++ b/tests/wpunit/Abstracts/Table_Abstract_Test.php @@ -9,20 +9,33 @@ use StellarWP\Shepherd\Contracts\Model; use StellarWP\Shepherd\Tables\Utility\Safe_Dynamic_Prefix; use StellarWP\DB\DB; +use StellarWP\Schema\Collections\Column_Collection; +use StellarWP\Schema\Columns\ID; +use StellarWP\Schema\Columns\String_Column; +use StellarWP\Schema\Tables\Table_Schema; class Dummy_Table extends Table_Abstract { protected static $base_table_name = 'pi_%s_dummy_table'; protected static $schema_slug = 'shepherd-%s-dummy-table'; protected static $uid_column = 'id'; - public static function get_columns(): array { + const SCHEMA_VERSION = '0.0.1-test'; + + public static function get_schema_history(): array { + $table_name = static::table_name( true ); + return [ - 'id' => [ 'type' => self::COLUMN_TYPE_BIGINT, 'length' => 20, 'unsigned' => true, 'auto_increment' => true ], - 'name' => [ 'type' => self::COLUMN_TYPE_VARCHAR, 'length' => 255 ], + static::SCHEMA_VERSION => function() use ( $table_name ) { + $columns = new Column_Collection(); + $columns[] = new ID( 'id' ); + $columns[] = new String_Column( 'name' ); + return new Table_Schema( $table_name, $columns ); + }, ]; } - protected static function get_model_from_array( array $model_array ): Model { + public static function transform_from_array( array $model_array ) { + return $model_array; } } diff --git a/tests/wpunit/Contracts/Task_Test.php b/tests/wpunit/Contracts/Task_Test.php index 136a4efc..b12ca78f 100644 --- a/tests/wpunit/Contracts/Task_Test.php +++ b/tests/wpunit/Contracts/Task_Test.php @@ -22,7 +22,7 @@ public function delete(): void {} public function get_table_interface(): Table_Abstract { return new class() extends Table_Abstract { - public static function get_columns(): array { + public static function get_schema_history(): array { return []; } }; diff --git a/tests/wpunit/Traits/Custom_Table_Query_Methods_Test.php b/tests/wpunit/Traits/Custom_Table_Query_Methods_Test.php index 6f1b3fd7..de7b18f5 100644 --- a/tests/wpunit/Traits/Custom_Table_Query_Methods_Test.php +++ b/tests/wpunit/Traits/Custom_Table_Query_Methods_Test.php @@ -8,6 +8,10 @@ use StellarWP\Shepherd\Abstracts\Table_Abstract; use StellarWP\Schema\Register; use StellarWP\Shepherd\Contracts\Model; +use StellarWP\Schema\Collections\Column_Collection; +use StellarWP\Schema\Columns\ID; +use StellarWP\Schema\Columns\String_Column; +use StellarWP\Schema\Tables\Table_Schema; class Dummy_Query_Table extends Table_Abstract { use Custom_Table_Query_Methods; @@ -20,15 +24,20 @@ class Dummy_Query_Table extends Table_Abstract { protected static $group = 'stellarwp_shepherd'; - public static function get_columns(): array { + public static function get_schema_history(): array { + $table_name = static::table_name( true ); return [ - 'id' => [ 'type' => self::COLUMN_TYPE_BIGINT, 'unsigned' => true, 'auto_increment' => true, 'php_type' => self::PHP_TYPE_INT ], - 'name' => [ 'type' => self::COLUMN_TYPE_VARCHAR, 'length' => 255, 'php_type' => self::PHP_TYPE_STRING ], - 'email' => [ 'type' => self::COLUMN_TYPE_VARCHAR, 'length' => 255, 'php_type' => self::PHP_TYPE_STRING ], + static::SCHEMA_VERSION => function() use ( $table_name ) { + $columns = new Column_Collection(); + $columns[] = new ID( 'id' ); + $columns[] = new String_Column( 'name' ); + return new Table_Schema( $table_name, $columns ); + }, ]; } - protected static function get_model_from_array( array $model_array ): Model { + public static function transform_from_array( array $model_array ) { + return $model_array; } } From 6802ea79e5e6f0a345e34f09b6089befd79fe430 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 17:42:37 +0300 Subject: [PATCH 07/17] Fix failing tests --- src/Abstracts/Model_Abstract.php | 2 +- src/Log.php | 2 +- src/Tables/AS_Logs.php | 2 +- src/Tables/Task_Logs.php | 2 +- .../wpunit/Abstracts/Table_Abstract_Test.php | 4 +- .../Custom_Table_Query_Methods_Test.php | 128 ------------------ 6 files changed, 6 insertions(+), 134 deletions(-) delete mode 100644 tests/wpunit/Traits/Custom_Table_Query_Methods_Test.php diff --git a/src/Abstracts/Model_Abstract.php b/src/Abstracts/Model_Abstract.php index 870cd3d1..56fe1ec1 100644 --- a/src/Abstracts/Model_Abstract.php +++ b/src/Abstracts/Model_Abstract.php @@ -114,7 +114,7 @@ public function delete(): void { */ public function to_array(): array { $table_interface = $this->get_table_interface(); - $columns = array_keys( $table_interface::get_columns() ); + $columns = $table_interface::get_columns()->get_names(); $model = []; foreach ( $columns as $column ) { diff --git a/src/Log.php b/src/Log.php index 7807da8d..382e9bd7 100644 --- a/src/Log.php +++ b/src/Log.php @@ -316,7 +316,7 @@ public function get_table_interface(): Table { */ public function to_array(): array { $table_interface = Task_Logs_Table::class; - $columns = array_keys( $table_interface::get_columns() ); + $columns = $table_interface::get_columns()->get_names(); $model = []; foreach ( $columns as $column ) { diff --git a/src/Tables/AS_Logs.php b/src/Tables/AS_Logs.php index d860c20a..3a0012a9 100644 --- a/src/Tables/AS_Logs.php +++ b/src/Tables/AS_Logs.php @@ -109,7 +109,7 @@ public static function transform_from_array( array $model_array ): Log { $log = new Log(); $log->set_id( $model_array['log_id'] ); $log->set_action_id( $model_array['action_id'] ); - $log->set_date( DateTime::createFromFormat( 'Y-m-d H:i:s', $model_array['log_date_gmt'] ) ); + $log->set_date( $model_array['log_date_gmt'] ); $message = explode( '||', $model_array['message'] ); $log->set_task_id( (int) ( $message[1] ?? 0 ) ); diff --git a/src/Tables/Task_Logs.php b/src/Tables/Task_Logs.php index 18523e6a..45947ccc 100644 --- a/src/Tables/Task_Logs.php +++ b/src/Tables/Task_Logs.php @@ -128,7 +128,7 @@ public static function transform_from_array( array $model_array ): Log { $log->set_id( $model_array['id'] ); $log->set_task_id( $model_array['task_id'] ); $log->set_action_id( $model_array['action_id'] ); - $log->set_date( DateTime::createFromFormat( 'Y-m-d H:i:s', $model_array['date'] ) ); + $log->set_date( $model_array['date'] ); $log->set_level( $model_array['level'] ); $log->set_type( $model_array['type'] ); $log->set_entry( $model_array['entry'] ); diff --git a/tests/wpunit/Abstracts/Table_Abstract_Test.php b/tests/wpunit/Abstracts/Table_Abstract_Test.php index 9adfed58..f26371d7 100644 --- a/tests/wpunit/Abstracts/Table_Abstract_Test.php +++ b/tests/wpunit/Abstracts/Table_Abstract_Test.php @@ -72,14 +72,14 @@ public function it_should_generate_correct_table_definition() { $this->assertStringContainsString( 'CREATE TABLE `wp_pi_tes_dummy_table`', $definition ); $this->assertStringContainsString( '`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT', $definition ); $this->assertStringContainsString( '`name` varchar(255) NOT NULL', $definition ); - $this->assertStringContainsString( 'PRIMARY KEY (`id`)', $definition ); + $this->assertStringContainsString( 'PRIMARY KEY (id`)', $definition ); } /** * @test */ public function it_should_return_empty_searchable_columns() { - $this->assertEquals( [], Dummy_Table::get_searchable_columns() ); + $this->assertEquals( [], Dummy_Table::get_searchable_columns()->get_names() ); } /** diff --git a/tests/wpunit/Traits/Custom_Table_Query_Methods_Test.php b/tests/wpunit/Traits/Custom_Table_Query_Methods_Test.php deleted file mode 100644 index de7b18f5..00000000 --- a/tests/wpunit/Traits/Custom_Table_Query_Methods_Test.php +++ /dev/null @@ -1,128 +0,0 @@ - function() use ( $table_name ) { - $columns = new Column_Collection(); - $columns[] = new ID( 'id' ); - $columns[] = new String_Column( 'name' ); - return new Table_Schema( $table_name, $columns ); - }, - ]; - } - - public static function transform_from_array( array $model_array ) { - return $model_array; - } -} - -class Custom_Table_Query_Methods_Test extends WPTestCase { - /** - * @before - */ - public function install_tables(): void { - Register::table( Dummy_Query_Table::class ); - } - - /** - * @after - */ - public function drop_tables(): void { - Register::remove_table( Dummy_Query_Table::class ); - } - - /** - * @test - */ - public function it_should_insert_and_fetch_rows() { - Dummy_Query_Table::insert( [ 'name' => 'John Doe', 'email' => 'john@test.com' ] ); - Dummy_Query_Table::insert_many( [ - [ 'name' => 'Jane Doe', 'email' => 'jane@test.com' ], - [ 'name' => 'Peter Pan', 'email' => 'peter@test.com' ], - ] ); - - $results = iterator_to_array( Dummy_Query_Table::fetch_all() ); - $this->assertCount( 3, $results ); - $this->assertEquals( 'Jane Doe', $results[1]->name ); - } - - /** - * @test - */ - public function it_should_update_rows() { - Dummy_Query_Table::insert( [ 'name' => 'John Doe', 'email' => 'john@test.com' ] ); - $row = Dummy_Query_Table::fetch_first_where( "WHERE name = 'John Doe'" ); - - Dummy_Query_Table::update_single( [ 'id' => $row->id, 'name' => 'John Smith' ] ); - $updated_row = Dummy_Query_Table::fetch_first_where( "WHERE id = {$row->id}" ); - $this->assertEquals( 'John Smith', $updated_row->name ); - } - - /** - * @test - */ - public function it_should_delete_rows() { - Dummy_Query_Table::insert( [ 'name' => 'John Doe', 'email' => 'john@test.com' ] ); - $row = Dummy_Query_Table::fetch_first_where( "WHERE name = 'John Doe'" ); - - Dummy_Query_Table::delete( (int) $row->id ); - $this->assertNull( Dummy_Query_Table::fetch_first_where( "WHERE id = {$row->id}" ) ); - } - - /** - * @test - */ - public function it_should_upsert_rows() { - // Test insert - Dummy_Query_Table::upsert( [ 'name' => 'John Doe', 'email' => 'john@test.com' ] ); - $row = Dummy_Query_Table::fetch_first_where( "WHERE name = 'John Doe'" ); - $this->assertNotNull( $row ); - - // Test update - Dummy_Query_Table::upsert( [ 'id' => $row->id, 'name' => 'John Smith' ] ); - $updated_row = Dummy_Query_Table::fetch_first_where( "WHERE id = {$row->id}" ); - $this->assertEquals( 'John Smith', $updated_row->name ); - } - - /** - * @test - */ - public function it_should_paginate_results() { - for ( $i = 0; $i < 10; $i++ ) { - Dummy_Query_Table::insert( [ 'name' => "User {$i}", 'email' => "user{$i}@test.com" ] ); - } - - $page1 = Dummy_Query_Table::paginate( [], 5, 1 ); - $this->assertCount( 5, $page1 ); - $this->assertEquals( 'User 0', $page1[0]->name ); - - $page2 = Dummy_Query_Table::paginate( [], 5, 2 ); - $this->assertCount( 5, $page2 ); - $this->assertEquals( 'User 5', $page2[0]->name ); - } -} From 0fba82052e76ecccc509788b84103396b00565e9 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 17:55:23 +0300 Subject: [PATCH 08/17] Fixing static analysis --- phpstan.neon.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 8dddba4f..023eeb9b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -24,6 +24,8 @@ parameters: - %currentWorkingDirectory%/src ignoreErrors: + - '#Cannot assign new offset to.*Column_Collection#' + - '#StellarWP\\Schema\\Collections\\Column_Collection does not accept StellarWP\\Schema\\Columns\\Contracts\\#' # Uses func_get_args() - '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#' # Uses func_get_args() From e760f545da379c900b6c6a284ad21392346860a7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 1 Oct 2025 14:55:53 +0000 Subject: [PATCH 09/17] chore: autopublish 2025-10-01T14:55:53Z --- src/Tables/AS_Logs.php | 1 - src/Tables/Task_Logs.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Tables/AS_Logs.php b/src/Tables/AS_Logs.php index 3a0012a9..4602a3ef 100644 --- a/src/Tables/AS_Logs.php +++ b/src/Tables/AS_Logs.php @@ -12,7 +12,6 @@ use StellarWP\Shepherd\Abstracts\Table_Abstract; use StellarWP\Shepherd\Log; use StellarWP\Shepherd\Config; -use DateTime; use StellarWP\Schema\Collections\Column_Collection; use StellarWP\Schema\Columns\ID; use StellarWP\Schema\Columns\Referenced_ID; diff --git a/src/Tables/Task_Logs.php b/src/Tables/Task_Logs.php index 45947ccc..62084469 100644 --- a/src/Tables/Task_Logs.php +++ b/src/Tables/Task_Logs.php @@ -11,7 +11,6 @@ use StellarWP\Shepherd\Abstracts\Table_Abstract; use StellarWP\Shepherd\Log; -use DateTime; use StellarWP\Schema\Columns\Created_At; use StellarWP\Schema\Columns\ID; use StellarWP\Schema\Columns\Referenced_ID; From e8f7462718b8fcf952961a679089dc84da1e045c Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 19:01:10 +0300 Subject: [PATCH 10/17] Update schema --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index afef8a85..02ab28da 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "require": { "php": ">=7.4", "stellarwp/db": "^1.1", - "stellarwp/schema": "^3.1", + "stellarwp/schema": "dev-feat/adding-the-order-by-param-in-get-all-by", "woocommerce/action-scheduler": "3.9.3", "psr/log": "^1.1" }, From a4bbd48a78f9c03f4ccf1343ffc7481f73004f66 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 19:19:32 +0300 Subject: [PATCH 11/17] Update method for phpstan --- tests/wpunit/Abstracts/Table_Abstract_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/wpunit/Abstracts/Table_Abstract_Test.php b/tests/wpunit/Abstracts/Table_Abstract_Test.php index f26371d7..08702f5d 100644 --- a/tests/wpunit/Abstracts/Table_Abstract_Test.php +++ b/tests/wpunit/Abstracts/Table_Abstract_Test.php @@ -72,7 +72,7 @@ public function it_should_generate_correct_table_definition() { $this->assertStringContainsString( 'CREATE TABLE `wp_pi_tes_dummy_table`', $definition ); $this->assertStringContainsString( '`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT', $definition ); $this->assertStringContainsString( '`name` varchar(255) NOT NULL', $definition ); - $this->assertStringContainsString( 'PRIMARY KEY (id`)', $definition ); + $this->assertStringContainsString( 'PRIMARY KEY (id)', $definition ); } /** From d8a82fe80789bb657ddd1df63ab4a03409c0ecc6 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Wed, 1 Oct 2025 22:54:28 +0300 Subject: [PATCH 12/17] Updating shcema requirements --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 02ab28da..b067c07f 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "require": { "php": ">=7.4", "stellarwp/db": "^1.1", - "stellarwp/schema": "dev-feat/adding-the-order-by-param-in-get-all-by", + "stellarwp/schema": "^3.1.1", "woocommerce/action-scheduler": "3.9.3", "psr/log": "^1.1" }, From 24a2a8a0c2b0e380fa6ea319056e8d9f1cd55ace Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Thu, 2 Oct 2025 00:13:17 +0300 Subject: [PATCH 13/17] Updates schema version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b067c07f..3492028e 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "require": { "php": ">=7.4", "stellarwp/db": "^1.1", - "stellarwp/schema": "^3.1.1", + "stellarwp/schema": "dev-fix/error-on-update-evaluation", "woocommerce/action-scheduler": "3.9.3", "psr/log": "^1.1" }, From 83bbf9f9e4a42eb51aae9d4be08187e261ba2eb8 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Thu, 2 Oct 2025 00:25:45 +0300 Subject: [PATCH 14/17] Updated release date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1863105c..c5131da9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard. -## [0.0.8] 2025-10-01 +## [0.0.8] 2025-10-02 * Feature - Update the stellarwp/schema library to v3. * Fix - Only delete task logs from the Task_Logs table when using DB_Logger in Provider::delete_tasks_on_action_deletion. From a448d9f74edb8e2307a061592914a6856da3bd8c Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Thu, 2 Oct 2025 15:10:41 +0300 Subject: [PATCH 15/17] Made readability improvements --- src/Tables/AS_Logs.php | 30 ++++++++++++++++++------------ src/Tables/Task_Logs.php | 34 +++++++++++++++++++++------------- src/Tables/Tasks.php | 30 +++++++++++++++++++----------- 3 files changed, 58 insertions(+), 36 deletions(-) diff --git a/src/Tables/AS_Logs.php b/src/Tables/AS_Logs.php index 4602a3ef..597e2d27 100644 --- a/src/Tables/AS_Logs.php +++ b/src/Tables/AS_Logs.php @@ -65,22 +65,28 @@ class AS_Logs extends Table_Abstract { * @return array The schema history for the table. */ public static function get_schema_history(): array { - $table_name = self::table_name( true ); - return [ - self::SCHEMA_VERSION => function () use ( $table_name ) { - $columns = new Column_Collection(); - $columns[] = new ID( 'log_id' ); - $columns[] = new Referenced_ID( 'action_id' ); - $columns[] = new String_Column( 'message' ); - $columns[] = ( new Datetime_Column( 'log_date_gmt' ) )->set_nullable( true ); - $columns[] = ( new Datetime_Column( 'log_date_local' ) )->set_nullable( true ); - - return new Table_Schema( $table_name, $columns ); - }, + self::SCHEMA_VERSION => [ __CLASS__, 'get_schema_version_0_0_1' ], ]; } + /** + * Gets the schema for version 0.0.1. + * + * @since 0.0.8 + * + * @return Table_Schema The schema for version 0.0.1. + */ + public static function get_schema_version_0_0_1(): Table_Schema { + $columns = new Column_Collection(); + $columns[] = new ID( 'log_id' ); + $columns[] = new Referenced_ID( 'action_id' ); + $columns[] = new String_Column( 'message' ); + $columns[] = ( new Datetime_Column( 'log_date_gmt' ) )->set_nullable( true ); + $columns[] = ( new Datetime_Column( 'log_date_local' ) )->set_nullable( true ); + return new Table_Schema( self::table_name( true ), $columns ); + } + /** * Gets the logs by task ID. * diff --git a/src/Tables/Task_Logs.php b/src/Tables/Task_Logs.php index 62084469..538ce2c2 100644 --- a/src/Tables/Task_Logs.php +++ b/src/Tables/Task_Logs.php @@ -83,23 +83,31 @@ class Task_Logs extends Table_Abstract { * @return array The schema history for the table. */ public static function get_schema_history(): array { - $table_name = self::table_name( true ); return [ - self::SCHEMA_VERSION => function () use ( $table_name ) { - $columns = new Column_Collection(); - $columns[] = new ID( 'id' ); - $columns[] = new Referenced_ID( 'task_id' ); - $columns[] = new Referenced_ID( 'action_id' ); - $columns[] = new Created_At( 'date' ); - $columns[] = ( new String_Column( 'level' ) )->set_length( 191 )->set_is_index( true ); - $columns[] = ( new String_Column( 'type' ) )->set_length( 191 )->set_is_index( true ); - $columns[] = ( new Text_Column( 'entry' ) )->set_type( Column_Types::LONGTEXT ); - - return new Table_Schema( $table_name, $columns ); - }, + self::SCHEMA_VERSION => [ __CLASS__, 'get_schema_version_0_0_3' ], ]; } + /** + * Gets the schema for version 0.0.3. + * + * @since 0.0.8 + * + * @return Table_Schema The schema for version 0.0.3. + */ + public static function get_schema_version_0_0_3(): Table_Schema { + $columns = new Column_Collection(); + $columns[] = new ID( 'id' ); + $columns[] = new Referenced_ID( 'task_id' ); + $columns[] = new Referenced_ID( 'action_id' ); + $columns[] = new Created_At( 'date' ); + $columns[] = ( new String_Column( 'level' ) )->set_length( 191 )->set_is_index( true ); + $columns[] = ( new String_Column( 'type' ) )->set_length( 191 )->set_is_index( true ); + $columns[] = ( new Text_Column( 'entry' ) )->set_type( Column_Types::LONGTEXT ); + + return new Table_Schema( self::table_name( true ), $columns ); + } + /** * Gets the logs by task ID. * diff --git a/src/Tables/Tasks.php b/src/Tables/Tasks.php index 6485267b..9f007b32 100644 --- a/src/Tables/Tasks.php +++ b/src/Tables/Tasks.php @@ -84,21 +84,29 @@ class Tasks extends Table_Abstract { * @return array The schema history for the table. */ public static function get_schema_history(): array { - $table_name = self::table_name( true ); return [ - self::SCHEMA_VERSION => function () use ( $table_name ) { - $columns = new Column_Collection(); - $columns[] = new ID( 'id' ); - $columns[] = new Referenced_ID( 'action_id' ); - $columns[] = ( new String_Column( 'class_hash' ) )->set_length( 191 )->set_is_index( true ); - $columns[] = ( new String_Column( 'args_hash' ) )->set_length( 191 )->set_is_index( true ); - $columns[] = ( new Text_Column( 'data' ) )->set_nullable( true ); - $columns[] = ( new Integer_Column( 'current_try' ) )->set_length( 20 )->set_signed( false )->set_default( 0 ); - return new Table_Schema( $table_name, $columns ); - }, + self::SCHEMA_VERSION => [ __CLASS__, 'get_schema_version_0_0_3' ], ]; } + /** + * Gets the schema for version 0.0.3. + * + * @since 0.0.8 + * + * @return Table_Schema The schema for version 0.0.3. + */ + public static function get_schema_version_0_0_3(): Table_Schema { + $columns = new Column_Collection(); + $columns[] = new ID( 'id' ); + $columns[] = new Referenced_ID( 'action_id' ); + $columns[] = ( new String_Column( 'class_hash' ) )->set_length( 191 )->set_is_index( true ); + $columns[] = ( new String_Column( 'args_hash' ) )->set_length( 191 )->set_is_index( true ); + $columns[] = ( new Text_Column( 'data' ) )->set_nullable( true ); + $columns[] = ( new Integer_Column( 'current_try' ) )->set_length( 20 )->set_signed( false )->set_default( 0 ); + return new Table_Schema( self::table_name( true ), $columns ); + } + /** * Gets a task by its action ID. * From 621bcc8bd768997d268763dfa0ce3ae0bbc96781 Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Thu, 2 Oct 2025 15:44:41 +0300 Subject: [PATCH 16/17] replacing __CLASS__ with self::class --- src/Config.php | 2 +- src/Tables/AS_Logs.php | 2 +- src/Tables/Task_Logs.php | 2 +- src/Tables/Tasks.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Config.php b/src/Config.php index 76db1ce9..98ce62a5 100644 --- a/src/Config.php +++ b/src/Config.php @@ -89,7 +89,7 @@ public static function get_container(): ContainerInterface { */ public static function get_hook_prefix(): string { if ( ! static::$hook_prefix ) { - $class = __CLASS__; + $class = self::class; throw new RuntimeException( "You must specify a hook prefix for your project with {$class}::set_hook_prefix()" ); } diff --git a/src/Tables/AS_Logs.php b/src/Tables/AS_Logs.php index 597e2d27..df451386 100644 --- a/src/Tables/AS_Logs.php +++ b/src/Tables/AS_Logs.php @@ -66,7 +66,7 @@ class AS_Logs extends Table_Abstract { */ public static function get_schema_history(): array { return [ - self::SCHEMA_VERSION => [ __CLASS__, 'get_schema_version_0_0_1' ], + self::SCHEMA_VERSION => [ self::class, 'get_schema_version_0_0_1' ], ]; } diff --git a/src/Tables/Task_Logs.php b/src/Tables/Task_Logs.php index 538ce2c2..31a15245 100644 --- a/src/Tables/Task_Logs.php +++ b/src/Tables/Task_Logs.php @@ -84,7 +84,7 @@ class Task_Logs extends Table_Abstract { */ public static function get_schema_history(): array { return [ - self::SCHEMA_VERSION => [ __CLASS__, 'get_schema_version_0_0_3' ], + self::SCHEMA_VERSION => [ self::class, 'get_schema_version_0_0_3' ], ]; } diff --git a/src/Tables/Tasks.php b/src/Tables/Tasks.php index 9f007b32..5f86e7e2 100644 --- a/src/Tables/Tasks.php +++ b/src/Tables/Tasks.php @@ -85,7 +85,7 @@ class Tasks extends Table_Abstract { */ public static function get_schema_history(): array { return [ - self::SCHEMA_VERSION => [ __CLASS__, 'get_schema_version_0_0_3' ], + self::SCHEMA_VERSION => [ self::class, 'get_schema_version_0_0_3' ], ]; } From ee90ee87a209b2c91f12383bffb04fb8aab5d8bf Mon Sep 17 00:00:00 2001 From: Dimitrios Pantazis Date: Thu, 2 Oct 2025 15:45:18 +0300 Subject: [PATCH 17/17] Updating schema to 3.1.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3492028e..3c482cc0 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "require": { "php": ">=7.4", "stellarwp/db": "^1.1", - "stellarwp/schema": "dev-fix/error-on-update-evaluation", + "stellarwp/schema": "^3.1.2", "woocommerce/action-scheduler": "3.9.3", "psr/log": "^1.1" },