+// Add ALTER TABLE `foo` DROP sql if not found
+function addExtensionDropTableColumnSql ($tableName, $columnName) {
+ // Assert on all
+ assert((!empty($tableName)) && (!empty($columnName)));
+
+ // Is the column there?
+ if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName, isInstaller())) {
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName);
+
+ // Then add it
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` DROP `' . $columnName . '`');
+ } elseif (isDebugModeEnabled()) {
+ // Add debug line
+ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName . ': does not exist.');
+ }
+}
+
+// Add ALTER TABLE `foo` DROP INDEX sql if not found
+function addExtensionDropTableIndexSql ($tableName, $indexName) {
+ // Assert on all
+ assert((!empty($tableName)) && (!empty($indexName)));
+
+ // Is the column there?
+ if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstaller())) {
+ // Debug message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName);
+
+ // Then add it
+ addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` DROP INDEX `' . $indexName . '`');
+ } elseif (isDebugModeEnabled()) {
+ // Add debug line
+ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName . ': does not exist.');
+ }
+}
+
+// Add configuration entry if not found for actual extension
+function addConfigAddSql ($columnName, $columnSql) {
+ // Call inner function
+ addExtensionAddTableColumnSql('config', $columnName, $columnSql);
+}
+
+// Drop configuration entry if found for actual extension
+function addConfigDropSql ($columnName) {
+ // Call inner function
+ addExtensionDropTableColumnSql('config', $columnName);
+}
+
+// Change configuration entry for actual extension
+function addConfigChangeSql ($oldColumnName, $newColumnName, $columnSql) {
+ // Add the SQL statement
+ addExtensionChangeTableColumnSql('config', $oldColumnName, $newColumnName, $columnSql);
+}
+
+/**
+ * Checks if given subject is found and if not, adds an SQL query to the
+ * extension registration queue.
+ */
+function registerExtensionPointsData ($subject, $columnName, $lockedMode, $paymentMethod) {
+ // Assert on all
+ assert((!empty($subject)) && (!empty($columnName)) && (!empty($lockedMode)) && (!empty($paymentMethod)));
+ assert((in_array($lockedMode, array('LOCKED', 'UNLOCKED'))) && (in_array($paymentMethod, array('DIRECT', 'REFERRAL'))));
+
+ // Is the suffix '_ref' not set?
+ if (!ifSubjectHasReferralSuffix($subject)) {
+ // Register this first
+ registerExtensionPointsData($subject . '_ref', $columnName, $lockedMode, $paymentMethod);
+ } // END - if
+
+ // Default is old extension version
+ $add = '';
+
+ // Is the extension equal or newer 0.8.9?
+ if (((isInstaller()) && ((getExtensionMode() == 'setup') || (getExtensionMode() == 'update'))) || (isExtensionInstalledAndNewer('sql_patches', '0.8.9'))) {
+ // Then add provider
+ $add = " AND `account_provider`='EXTENSION'";
+ } // END - if
+
+ // Is the 'subject' there?
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ifSqlTableExists(points_data)=' . ifSqlTableExists('points_data') . ',getExtensionMode()=' . getExtensionMode() . ',add=' . $add);
+ if (((!ifSqlTableExists('points_data')) && ((getExtensionMode() == 'setup') || (getExtensionMode() == 'update'))) || (countSumTotalData($subject, 'points_data', 'id', 'subject', TRUE, $add) == 0)) {
+ // Not found so:
+ if ((!isInstaller()) && (isset($GLOBALS['previous_extension'][getCurrentExtensionName()])) && (!ifSqlTableExists('points_data'))) {
+ // This may happen (but when?)
+ // @TODO Is this really neccessary?
+ $dummy = $GLOBALS['previous_extension'][getCurrentExtensionName()];
+ reportBug(__FUNCTION__, __LINE__, 'dummy[' . gettype($dummy) . ']=' . $dummy . ',getCurrentExtensionName()=' . getCurrentExtensionName() . ' - Under development, please report this!');
+ } // END - if
+
+ // With or without account_provider?
+ if (((isInstaller()) && ((getExtensionMode() == 'setup') || (getExtensionMode() == 'update'))) || (isExtensionInstalledAndNewer('sql_patches', '0.8.9'))) {
+ // Add account_provider
+ addExtensionSql(sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`subject`, `column_name`, `locked_mode`, `payment_method`, `account_provider`) VALUES ('%s','%s','%s','%s','EXTENSION')",
+ $subject,
+ $columnName,
+ $lockedMode,
+ $paymentMethod
+ ));
+ } else {
+ // ... add an SQL query
+ addExtensionSql(sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_points_data` (`subject`, `column_name`, `locked_mode`, `payment_method`) VALUES ('%s','%s','%s','%s')",
+ $subject,
+ $columnName,
+ $lockedMode,
+ $paymentMethod
+ ));
+ }
+ } // END - if
+}
+
+/**
+ * Checks if given subject is found and if so, adds an SQL query to the
+ * extension unregistration queue.
+ */
+function unregisterExtensionPointsData ($subject) {
+ // Is the suffix '_ref' not set?
+ if (!ifSubjectHasReferralSuffix($subject)) {
+ // Unregister this first
+ unregisterExtensionPointsData($subject . '_ref');
+ } // END - if
+
+ // Default is old extension version
+ $add = '';
+
+ // Is the extension equal or newer 0.8.9?
+ if (isExtensionInstalledAndNewer('sql_patches', '0.8.9')) {
+ // Then add provider
+ $add = " AND `account_provider`='EXTENSION'";
+ } // END - if
+
+ // Is the 'subject' there?
+ if (countSumTotalData($subject, 'points_data', 'id', 'subject', TRUE, $add) == 1) {
+ // Found one or more, so add an SQL query
+ addExtensionSql(sprintf("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_points_data` WHERE `subject`='%s'" . $add . " LIMIT 1",
+ $subject
+ ));
+ } // END - if
+}
+