PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 158
Lasso Lite – Affiliate Link Manager & Product Displays v158
158 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 All 57 releases
simple-urls / classes / class-update-db.php

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

113 lines 2.6 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 use LassoLite\Classes\Setting;
18
19 /**
20 * Update_DB
21 */
22 class Update_DB {
23 /**
24 * Update_DB constructor.
25 */
26 public function __construct() {
27
28 if ( ! Helper::is_lite_using_new_ui() ) {
29 return;
30 }
31
32 // ? Perform any additional schema changes and data updates/upgrades.
33 $this->update_lasso_database();
34
35 $this->update_version();
36 }
37
38 /**
39 * Get version from database
40 */
41 public function get_version() {
42 $version = Helper::get_option( 'lasso_version', 100 );
43 $version = floatval( $version );
44
45 return $version;
46 }
47
48 /**
49 * Set version and save it to the option table
50 */
51 public function update_version() {
52 Helper::update_option( 'lasso_version', LASSO_LITE_VERSION );
53 }
54
55 /**
56 * Create all Lasso Lite tables
57 */
58 public static function create_tables() {
59 ( new Amazon_Products() )->create_table();
60 ( new Url_Details() )->create_table();
61 ( new Revert() )->create_table();
62 }
63
64
65 /**
66 * Update database structure for new version
67 */
68 public function update_lasso_database() {
69 $version = $this->get_version();
70
71 if ( $version < 108 ) {
72 $this->create_tables();
73 }
74
75 if ( $version < 113 ) {
76 ( new Amazon_Products() )->create_table();
77 $this->update_rating_and_review_data_from_aawp();
78 }
79
80 if ( $version < 129 ) {
81 Setting::set_setting( 'auto_upgrade_eligible_links', true );
82 }
83
84 if ( $version < 152 && (int) LASSO_LITE_VERSION >= 152 ) {
85 ( new Url_Details() )->update_for_v152();
86 ( new Revert() )->update_for_v152();
87 }
88
89 // Beacon /js/e rewrite is registered in new code; upgrader runs the old callback.
90 if ( $version < 154 && (int) LASSO_LITE_VERSION >= 154 ) {
91 Helper::update_option( 'pending_vanity_rewrite_flush', '1' );
92 }
93 }
94
95 /**
96 * Update rating and reviews data from AAWP product table to Lasso amazon table, so we can support aawp fields shortcode
97 */
98 public function update_rating_and_review_data_from_aawp() {
99 $lite_amazon_product_table = ( new Amazon_Products() )->get_table_name();
100 $aawp_product_table = Model::get_wp_table_name( 'aawp_products' );
101 if ( Model::table_exists( $aawp_product_table ) ) {
102 $sql = '
103 UPDATE ' . $lite_amazon_product_table . ' AS lap
104 INNER JOIN ' . $aawp_product_table . ' AS aawpp ON lap.amazon_id = aawpp.asin
105 SET lap.rating = IF(aawpp.rating IS NOT NULL, aawpp.rating, lap.rating),
106 lap.reviews = IF(aawpp.reviews IS NOT NULL, aawpp.reviews, lap.reviews)
107 ';
108
109 Model::query( $sql );
110 }
111 }
112 }
113