]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions/ext-coupon.php
Required fix for NULL vs. 0 in user_points
[mailer.git] / inc / extensions / ext-coupon.php
index ea480f402bc8dea476999a3a3457bac10b355423..7f9ab18d82718bfb5d3844c7e5cbc363772f183e 100644 (file)
@@ -43,26 +43,26 @@ if (!defined('__SECURITY')) {
 } // END - if
 
 // Version number
-setThisExtensionVersion('0.0');
+setThisExtensionVersion('0.0.1');
 
 // Version history array (add more with , '0.1' and so on)
-setExtensionVersionHistory(array('0.0'));
-
-// This extension is in development (non-productive)
-enableExtensionProductive(false);
+setExtensionVersionHistory(array('0.0.0', '0.0.1'));
 
 switch (getExtensionMode()) {
-       case 'register': // Do stuff when installtion is running (modules.php?module=admin&action=login is called)
+       case 'register': // Do stuff when installtion is running
+               // This extension requires an up-to-date ext-user
+               addExtensionDependency('user');
+
                // Coupon data
                addDropTableSql('coupon_data');
                addCreateTableSql('coupon_data', "(
 `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
-`timestamp_created` TIMESTAMP NULL DEFAULT NULL,
-`timestamp_expired` TIMESTAMP NULL DEFAULT NULL,
+`coupon_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
+`coupon_expired` TIMESTAMP NULL DEFAULT NULL,
 `coupon_type` ENUM('CODE','API') NOT NULL DEFAULT 'CODE',
 `total_created` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-`total_used` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
-`points` FLOAT(20,5) NOT NULL DEFAULT 0.00000,
+`total_cashed` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0,
+`points` FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 0.00000,
 `coupon_description` TEXT,
 PRIMARY KEY (`id`)
 ) TYPE = {?_TABLE_TYPE?} CHARACTER SET utf8 COLLATE utf8_general_ci COMMENT = 'Created coupons'");
@@ -82,7 +82,9 @@ UNIQUE KEY (`coupon_code`)
 
                // Configuration entries
                addConfigAddSql('coupon_default_time', 'BIGINT(20) NOT NULL DEFAULT ' . (getOneDay() * 7));
-               addConfigAddSql('coupon_default_points', 'FLOAT(20,5) NOT NULL DEFAULT 100.00000');
+               addConfigAddSql('coupon_default_points', 'FLOAT(20,5) UNSIGNED NOT NULL DEFAULT 100.00000');
+               addConfigAddSql('coupon_autopurge_time', 'BIGINT(20) NOT NULL DEFAULT ' . (getOneDay() * 7));
+               addConfigAddSql('coupon_userid', 'BIGINT(20) UNSIGNED NOT NULL DEFAULT 0');
 
                // User data table
                addExtensionSql("ALTER TABLE `{?_MYSQL_PREFIX?}_user_data` ADD `receiving_coupons` ENUM('Y','N') NOT NULL DEFAULT 'Y'");
@@ -97,6 +99,9 @@ UNIQUE KEY (`coupon_code`)
                addMemberMenuSql('coupon', NULL, 'Gutscheine', 'N', 'Y', 3);
                addMemberMenuSql('coupon', 'cash_coupon', 'Gutschein einlösen', 'N', 'Y', 1);
                addMemberMenuSql('coupon', 'list_coupon', 'Eingelöste auflisten', 'N', 'Y', 2);
+
+               // Add filter (for changing user_points column dynamically
+               registerFilter('determine_points_column_name', 'COUPON_CHANGE_POINTS_COLUMN_NAME', false, true, isExtensionDryRun());
                break;
 
        case 'remove': // Do stuff when removing extension
@@ -105,22 +110,34 @@ UNIQUE KEY (`coupon_code`)
                addDropTableSql('user_coupons');
                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admin_menu` WHERE `action`='coupon' LIMIT 4");
                addExtensionSql("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_member_menu` WHERE `action`='coupon' LIMIT 3");
+
+               // Remove all filters
+               unregisterFilter(__FUNCTION__, __LINE__, 'determine_points_column_name', 'COUPON_CHANGE_POINTS_COLUMN_NAME', true, isExtensionDryRun());
                break;
 
        case 'activate': // Do stuff when admin activates this extension
                // SQL commands to run
-               addExtensionSql('');
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='Y', `locked`='N' WHERE `action`='coupon' LIMIT 3");
                break;
 
        case 'deactivate': // Do stuff when admin deactivates this extension
                // SQL commands to run
-               addExtensionSql('');
+               addExtensionSql("UPDATE `{?_MYSQL_PREFIX?}_member_menu` SET `visible`='N', `locked`='Y' WHERE `action`='coupon' LIMIT 3");
                break;
 
        case 'update': // Update an extension
                switch (getCurrentExtensionVersion()) {
                        case '0.0.1': // SQL queries for v0.0.1
-                               addExtensionSql('');
+                               addConfigDropSql('coupon_points_account');
+                               addConfigDropSql('coupon_payment_method');
+                               addConfigDropSql('coupon_locked_points_mode');
+
+                               // This extension's update requires an up-to-date ext-sql_patches and ext-order
+                               addExtensionDependency('sql_patches');
+                               addExtensionDependency('order');
+
+                               // Insert data in new table
+                               addExtensionSql("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`ext_name`,`column_name`,`locked_mode`,`payment_method`) VALUES('coupon','order_points','LOCKED','DIRECT')");
 
                                // Update notes (these will be set as task text!)
                                setExtensionUpdateNotes('');