PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 113
Lasso Lite – Affiliate Link Manager & Product Displays v113
157 155 156 154 153 152 151 150 149 148 trunk 0.9.9 104 105 106 107 108 109 110 111 112 113 114 115 116 All 56 releases
simple-urls / classes / class-update-db.php

class-update-db.php in Lasso Lite – Affiliate Link Manager & Product Displays 113, at classes/class-update-db.php

97 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Declare class Update_DB
4 *
5 * @package Update_DB
6 */
7
8 namespace LassoLite\Classes;
9
10 use LassoLite\Classes\Helper;
11
12 use LassoLite\Models\Amazon_Products;
13 use LassoLite\Models\Model;
14 use LassoLite\Models\Url_Details;
15 use LassoLite\Models\Revert;
16
17 /**
18 * Update_DB
19 */
20 class Update_DB {
21 /**
22 * Update_DB constructor.
23 */
24 public function __construct() {
25
26 if ( ! Helper::is_lite_using_new_ui() ) {
27 return;
28 }
29
30 // ? Perform any additional schema changes and data updates/upgrades.
31 $this->update_lasso_database();
32
33 $this->update_version();
34 }
35
36 /**
37 * Get version from database
38 */
39 public function get_version() {
40 $version = Helper::get_option( 'lasso_version', 100 );
41 $version = floatval( $version );
42
43 return $version;
44 }
45
46 /**
47 * Set version and save it to the option table
48 */
49 public function update_version() {
50 Helper::update_option( 'lasso_version', LASSO_LITE_VERSION );
51 }
52
53 /**
54 * Create all Lasso Lite tables
55 */
56 public static function create_tables() {
57 ( new Amazon_Products() )->create_table();
58 ( new Url_Details() )->create_table();
59 ( new Revert() )->create_table();
60 }
61
62
63 /**
64 * Update database structure for new version
65 */
66 public function update_lasso_database() {
67 $version = $this->get_version();
68
69 if ( $version < 108 ) {
70 $this->create_tables();
71 }
72
73 if ( $version < 113 ) {
74 ( new Amazon_Products() )->create_table();
75 $this->update_rating_and_review_data_from_aawp();
76 }
77 }
78
79 /**
80 * Update rating and reviews data from AAWP product table to Lasso amazon table, so we can support aawp fields shortcode
81 */
82 public function update_rating_and_review_data_from_aawp() {
83 $lite_amazon_product_table = ( new Amazon_Products() )->get_table_name();
84 $aawp_product_table = Model::get_wp_table_name( 'aawp_products' );
85 if ( Model::table_exists( $aawp_product_table ) ) {
86 $sql = '
87 UPDATE ' . $lite_amazon_product_table . ' AS lap
88 INNER JOIN ' . $aawp_product_table . ' AS aawpp ON lap.amazon_id = aawpp.asin
89 SET lap.rating = IF(aawpp.rating IS NOT NULL, aawpp.rating, lap.rating),
90 lap.reviews = IF(aawpp.reviews IS NOT NULL, aawpp.reviews, lap.reviews)
91 ';
92
93 Model::query( $sql );
94 }
95 }
96 }
97