Skip to content

Commit

Permalink
Updates to 6.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Woo committed Dec 26, 2024
1 parent bea5e11 commit 669e5b7
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 145 deletions.
6 changes: 3 additions & 3 deletions automatewoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: AutomateWoo
* Plugin URI: https://automatewoo.com
* Description: Powerful marketing automation for your WooCommerce store.
* Version: 6.1.3
* Version: 6.1.4
* Author: WooCommerce
* Author URI: https://woocommerce.com
* License: GPLv3
Expand All @@ -13,7 +13,7 @@
* Tested up to: 6.7
* Requires Plugins: woocommerce
* WC requires at least: 7.9
* WC tested up to: 9.4
* WC tested up to: 9.5
* Woo: 4652610:f6f1f8a56a16a3715b30b21fb557e78f
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -37,7 +37,7 @@
defined( 'ABSPATH' ) || exit;

define( 'AUTOMATEWOO_SLUG', 'automatewoo' );
define( 'AUTOMATEWOO_VERSION', '6.1.3' ); // WRCS: DEFINED_VERSION.
define( 'AUTOMATEWOO_VERSION', '6.1.4' ); // WRCS: DEFINED_VERSION.
define( 'AUTOMATEWOO_FILE', __FILE__ );
define( 'AUTOMATEWOO_PATH', __DIR__ );
define( 'AUTOMATEWOO_MIN_PHP_VER', '7.4.0' );
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** AutomateWoo Changelog ***

2024-12-25 - version 6.1.4
* Dev - Fix PHP unit tests - install svn.
* Fix - PHP 8.4 incompatible code.
* Tweak - WC 9.5 compatibility.

2024-12-03 - version 6.1.3
* Fix - Prevent translations from being called early.

Expand Down
111 changes: 61 additions & 50 deletions includes/Model.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

Expand Down Expand Up @@ -32,15 +31,15 @@ abstract class Model {
/**
* @return int
*/
function get_id() {
public function get_id() {
return $this->id ? (int) $this->id : 0;
}


/**
* @param int $id
*/
function set_id( $id ) {
public function set_id( $id ) {
$this->id = $id;
}

Expand All @@ -50,37 +49,39 @@ function set_id( $id ) {
*
* @param array $row
*/
function fill( $row ) {
public function fill( $row ) {
if ( ! is_array( $row ) ) {
return;
}

$this->data = $row;
$this->data = $row;
$this->original_data = $row;
$this->exists = true;
$this->exists = true;

do_action( 'automatewoo/object/load', $this );
}


/**
* @param $value string|int
* @param $field string
* @param string $field
* @param string|int $value
*/
function get_by( $field, $value ) {
public function get_by( $field, $value ) {

global $wpdb;

$row = $wpdb->get_row(
$wpdb->prepare( "
SELECT * FROM {$this->get_table_name()}
WHERE $field = %s
", $value
), ARRAY_A
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
"SELECT * FROM {$this->get_table_name()} WHERE $field = %s",
$value
),
ARRAY_A
);

if ( ! $row )
if ( ! $row ) {
return;
}

$this->fill( $row );
}
Expand All @@ -92,56 +93,56 @@ function get_by( $field, $value ) {
* @param string $key
* @return mixed
*/
function __get( $key ) {
public function __get( $key ) {
return $this->get_prop( $key );
}


/**
* Magic method for setting db fields
*
* @param $key
* @param $value
* @param string $key
* @param mixed $value
*/
function __set( $key, $value ) {
public function __set( $key, $value ) {
$this->set_prop( $key, $value );
}


/**
* @param $key
* @param $value
* @param string $key
* @param mixed $value
*/
function set_prop( $key, $value ) {
public function set_prop( $key, $value ) {

if ( is_array( $value ) && ! $value ) {
$value = ''; // convert empty arrays to blank
}

$this->data[$key] = $value;
$this->data[ $key ] = $value;
$this->changed_fields[] = $key;
}


/**
* @param $key
* @param string $key
* @return bool
*/
function has_prop( $key ) {
return isset( $this->data[$key] );
public function has_prop( $key ) {
return isset( $this->data[ $key ] );
}


/**
* @param $key
* @param string $key
* @return mixed
*/
function get_prop( $key ) {
if ( ! isset( $this->data[$key] ) ) {
public function get_prop( $key ) {
if ( ! isset( $this->data[ $key ] ) ) {
return false;
}

$value = $this->data[$key];
$value = $this->data[ $key ];
$value = maybe_unserialize( $value );

return $value;
Expand All @@ -151,10 +152,11 @@ function get_prop( $key ) {
/**
* @return Database_Table
*/
function get_table() {
public function get_table() {

if ( ! isset( $this->table_id ) ) {
trigger_error( sprintf( 'AutomateWoo - %s is an incompatible subclass of %s. You may need need to update your AutomateWoo add-ons.', get_called_class(), get_class()), E_USER_ERROR );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_die( sprintf( 'AutomateWoo - %s is an incompatible subclass of %s. You may need need to update your AutomateWoo add-ons.', get_called_class(), __CLASS__ ) );
}

return Database_Tables::get( $this->table_id );
Expand All @@ -164,7 +166,7 @@ function get_table() {
/**
* @return string
*/
function get_table_name() {
public function get_table_name() {
return $this->get_table()->get_name();
}

Expand Down Expand Up @@ -204,8 +206,7 @@ public function save() {
}

do_action( 'automatewoo/object/update', $this ); // cleans object cache
}
else {
} else {
$this->data = array_map( 'maybe_serialize', $this->data );

// insert row
Expand All @@ -216,10 +217,11 @@ public function save() {

if ( $wpdb->insert_id ) {
$this->exists = true;
$this->id = $wpdb->insert_id;
$this->id = $wpdb->insert_id;
} else {
$aw_catch_db_error = 'Error: '.$wpdb->last_error.' (Query: '.$wpdb->last_query.')';
Logger::critical( 'errors', sprintf( __( 'Could not insert \'%1$s\' item to database. AutomateWoo tables may not be installed. (%2$s)', 'automatewoo' ), $this->object_type, $aw_catch_db_error) );
$aw_catch_db_error = 'Error: ' . $wpdb->last_error . ' (Query: ' . $wpdb->last_query . ')';
/* translators: %1$s object type, %2$s DB error message and query */
Logger::critical( 'errors', sprintf( __( 'Could not insert \'%1$s\' item to database. AutomateWoo tables may not be installed. (%2$s)', 'automatewoo' ), $this->object_type, $aw_catch_db_error ) );

// Return here to prevent cache updates on error
return false;
Expand All @@ -231,7 +233,7 @@ public function save() {
// reset changed data
// important to reset after cache hooks
$this->changed_fields = [];
$this->original_data = $this->data;
$this->original_data = $this->data;

return true;
}
Expand All @@ -240,33 +242,42 @@ public function save() {
/**
* @return void
*/
function delete() {
public function delete() {
global $wpdb;

do_action( 'automatewoo/object/delete', $this ); // cleans object cache

if ( ! $this->exists ) return;
if ( ! $this->exists ) {
return;
}

$wpdb->query( $wpdb->prepare( "
DELETE FROM {$this->get_table_name()}
WHERE id = %d
", $this->get_id()
));
$wpdb->query(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
"DELETE FROM {$this->get_table_name()} WHERE id = %d",
$this->get_id()
)
);

$this->exists = false;
}


/**
* @param $column
* @param string $column
* @return bool|DateTime
*/
protected function get_date_column( $column ) {
if ( $column && $prop = $this->get_prop( $column ) ) {
return new DateTime( $prop );
if ( ! $column ) {
return false;
}

$prop = $this->get_prop( $column );
if ( ! $prop ) {
return false;
}

return false;
return new DateTime( $prop );
}


Expand Down
Loading

0 comments on commit 669e5b7

Please sign in to comment.