]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions-functions.php
Code moved to other include file:
[mailer.git] / inc / extensions-functions.php
index fda30577884c93a887959ad6f9ba5a85d0037846..3a5696cd6b90a77e1472341537133274bb0162fb 100644 (file)
@@ -120,7 +120,7 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $isDryRun = FA
        } // END - if
 
        // Load extension's own language file if not in test mode
-       if ((getExtensionMode() != 'test') && (ifExtensionHasLanguageFile($ext_name))) {
+       if ((getExtensionMode() != 'test') && (isExtensionLanguageFileReadable($ext_name))) {
                // Load it
                loadLanguageFile($ext_name);
        } // END - if
@@ -357,42 +357,47 @@ function registerExtension ($ext_name, $taskId, $isDryRun = FALSE, $ignoreUpdate
                                setSqlsArray(getExtensionSqls());
 
                                // Run installation pre-installation filters
-                               runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'enable_codes' => FALSE));
+                               runFilterChain('pre_extension_installed', array('dry_run' => isExtensionDryRun(), 'ext_installing' => TRUE, 'enable_codes' => FALSE));
+
+                               // Copy current name to save calls
+                               $currentName = getCurrentExtensionName();
 
                                // Register extension
-                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . getCurrentExtensionName() . '/' . getCurrentExtensionVersion() . ' - INSERT!');
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'insert=' . $currentName . '/' . getCurrentExtensionVersion() . ' - INSERT!');
                                if (isExtensionInstalledAndNewer('sql_patches', '0.0.6')) {
                                        // New way, with CSS
-                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss());
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $currentName . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion() . 'ext_css=' . getExtensionHasCss());
                                        SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`, `ext_has_css`) VALUES ('%s','%s','%s','%s')",
                                                array(
-                                                       getCurrentExtensionName(),
+                                                       $currentName,
                                                        getThisExtensionAlwaysActive(),
                                                        getCurrentExtensionVersion(),
                                                        getExtensionHasCss()
                                                ), __FUNCTION__, __LINE__);
                                } else {
                                        // Old way, no CSS
-                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion());
+                                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $currentName . ',always_active=' . getThisExtensionAlwaysActive() . ', ext_ver=' . getCurrentExtensionVersion());
                                        SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_extensions` (`ext_name`, `ext_active`, `ext_version`) VALUES ('%s','%s','%s')",
                                                array(
-                                                       getCurrentExtensionName(),
+                                                       $currentName,
                                                        getThisExtensionAlwaysActive(),
                                                        getCurrentExtensionVersion()
                                                ), __FUNCTION__, __LINE__);
                                }
 
-                               // Use the insert id as extension id and cache it for early usage
-                               $GLOBALS['cache_array']['extension']['ext_id'][getCurrentExtensionName()] = SQL_INSERTID();
-                               $GLOBALS['cache_array']['extension']['ext_name'][SQL_INSERTID()] = getCurrentExtensionName();
+                               /*
+                                * Use the insert id as extension id and "cache" all data for
+                                * this extension for early usage.
+                                */
+                               copyCurrentExtensionDataToCacheArray($ext_name, SQL_INSERTID());
 
                                // Mark it as installed
-                               $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = TRUE;
+                               $GLOBALS['ext_is_installed'][$currentName] = TRUE;
 
                                // Remove cache file(s) if extension is active
                                runFilterChain('post_extension_installed', array(
                                        'pool'     => 'extension',
-                                       'ext_name' => getCurrentExtensionName(),
+                                       'ext_name' => $currentName,
                                        'task_id'  => $taskId
                                ));
 
@@ -771,7 +776,7 @@ function updateExtension ($ext_name, $ext_ver, $isDryRun = FALSE, $ignoreDepende
                setSqlsArray(getExtensionSqls());
 
                // Run SQLs
-               runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'enable_codes' => FALSE));
+               runFilterChain('run_sqls', array('dry_run' => isExtensionDryRun(), 'ext_installing' => TRUE, 'enable_codes' => FALSE));
 
                if (isExtensionDryRun() === FALSE) {
                        // Run filters on success extension update
@@ -996,19 +1001,6 @@ function doDeactivateExtension ($ext_name, $inRebuild = FALSE) {
        );
 }
 
-// Checks whether the extension is older than given
-function isExtensionOlder ($ext_name, $ext_ver) {
-       // Get current extension version
-       $currVersion = getExtensionVersion($ext_name);
-
-       // Remove all dots from both versions
-       $currVersion = str_replace('.', '', $currVersion);
-       $ext_ver = str_replace('.', '', $ext_ver);
-
-       // Now compare both and return the result
-       return ($currVersion < $ext_ver);
-}
-
 // Creates a new task for updated extension
 function createExtensionUpdateTask ($adminId, $ext_name, $ext_ver, $notes) {
        // Create subject line
@@ -1164,20 +1156,20 @@ function addExtensionNotes ($ext_ver) {
                                // Initial release
                                $content = array(
                                        'ver'   => $ext_ver,
-                                       'notes' => '{--INITIAL_RELEASE--}'
+                                       'notes' => '{--ADMIN_EXTENSION_INITIAL_RELEASE--}'
                                );
                        } else {
                                // Not productive
                                $content = array(
                                        'ver'   => $ext_ver,
-                                       'notes' => '{--DEVELOPER_RELEASE--}'
+                                       'notes' => '{--ADMIN_EXTENSION_DEVELOPER_RELEASE--}'
                                );
                        }
                } else {
                        // No update notes found
                        $content = array(
                                'ver'   => $ext_ver,
-                               'notes' => '{--NO_UPDATE_NOTICES--}'
+                               'notes' => '{--ADMIN_EXTENSION_UPDATE_NOTICES_404--}'
                        );
                }
 
@@ -1556,10 +1548,14 @@ function initExtensionSqls ($force = FALSE) {
 
 // Adds SQLs to the SQLs array but "assigns" it with current extension name
 function addExtensionSql ($sql) {
+       // Copy current name/version to local variable
+       $currentName    = getCurrentExtensionName();
+       $currentVersion = getCurrentExtensionVersion();
+
        // Is is the array there?
-       if ((!isset($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()])) || (!is_array($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()]))) {
+       if ((!isset($GLOBALS['ext_sqls'][$currentName][$currentVersion])) || (!is_array($GLOBALS['ext_sqls'][$currentName][$currentVersion]))) {
                // Init array
-               $GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()] = array();
+               $GLOBALS['ext_sqls'][$currentName][$currentVersion] = array();
        } // END - if
 
        // Is the SQL statement empty?
@@ -1573,8 +1569,8 @@ function addExtensionSql ($sql) {
        } // END - if
 
        // Add it
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . getCurrentExtensionName() . ',ext_version=' . getCurrentExtensionVersion() . ',sql=' . $sql);
-       array_push($GLOBALS['ext_sqls'][getCurrentExtensionName()][getCurrentExtensionVersion()], $sql);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $currentName . ',ext_version=' . $currentVersion . ',sql=' . $sql);
+       array_push($GLOBALS['ext_sqls'][$currentName][$currentVersion], $sql);
 }
 
 // Getter for SQLs array for current extension
@@ -1763,8 +1759,8 @@ function getExtensionHasCss () {
        return $GLOBALS[__FUNCTION__][getCurrentExtensionName()][getCurrentTheme()];
 }
 
-// Checks whether the given extension has a language file
-function ifExtensionHasLanguageFile ($ext_name) {
+// Checks whether the given extension's language file is readable
+function isExtensionLanguageFileReadable ($ext_name) {
        // Is there cache?
        if (isset($GLOBALS['cache_array']['extension']['ext_lang'][$ext_name])) {
                // Count cache hits
@@ -1850,8 +1846,8 @@ CHARACTER SET utf8
 COLLATE utf8_general_ci
 COMMENT ' . chr(39) . $comment . chr(39));
        } else {
-               // Is already there, which should not happen
-               reportBug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
+               // Is already there
+               logDebugMessage(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created.');
        }
 }
 
@@ -1859,8 +1855,10 @@ COMMENT ' . chr(39) . $comment . chr(39));
 function addDropTableSql ($tableName) {
        // Is the table there?
        if (ifSqlTableExists($tableName)) {
-               // Then add it, non-existing tables can be ignored because it will
-               // happen with every newly installed extension.
+               /*
+                * Then add it, non-existing tables can be ignored because it will
+                * happen with every newly installed extension.
+                */
                addExtensionSql('DROP TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '`');
 
                // Mark it as gone
@@ -1870,6 +1868,9 @@ function addDropTableSql ($tableName) {
 
 // Adds a RENAME TABLE stament if 'from' table exist and 'to' table not
 function addRenameTableSql ($fromTable, $toTable) {
+       // Make sure both are not the same
+       assert($fromTable != $toTable);
+
        // Is renaming required?
        if ((ifSqlTableExists($fromTable)) && (!ifSqlTableExists($toTable))) {
                // Add it
@@ -2008,7 +2009,7 @@ function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
 // Add ALTER TABLE `foo` ADD sql if not found
 function addExtensionAddTableColumnSql ($tableName, $columnName, $columnSql) {
        // Is the column there?
-       if (!ifSqlColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) {
+       if (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName, isInstallationPhase())) {
                // Then add it
                addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD `' . $columnName . '` ' . $columnSql);
        } elseif (isDebugModeEnabled()) {
@@ -2017,10 +2018,46 @@ function addExtensionAddTableColumnSql ($tableName, $columnName, $columnSql) {
        }
 }
 
+// Add ALTER TABLE `foo` ADD INDEX sql if not found
+function addExtensionAddTableIndexSql ($tableName, $indexName, $columnSql) {
+       // Is the column there?
+       if (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstallationPhase())) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD INDEX `' . $indexName . '` ' . $columnSql);
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName . ',columnSql=' . $columnSql . ': does already exist.');
+       }
+}
+
+// Add ALTER TABLE `foo` ADD UNIQUE INDEX sql if not found
+function addExtensionAddTableUniqueSql ($tableName, $indexName, $columnSql) {
+       // Is the column there?
+       if (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstallationPhase())) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD UNIQUE INDEX `' . $indexName . '` ' . $columnSql);
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName . ',columnSql=' . $columnSql . ': does already exist.');
+       }
+}
+
+// Add ALTER TABLE `foo` ADD FULLTEXT sql if not found
+function addExtensionAddTableFulltextSql ($tableName, $indexName, $columnSql) {
+       // Is the column there and MyISAM engine? (InnoDB doesn't support FULLTEXT)
+       if ((getTableType() == 'MyISAM') && (!ifSqlTableIndexExist('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstallationPhase()))) {
+               // Then add it
+               addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ADD FULLTEXT `' . $indexName . '` ' . $columnSql);
+       } elseif (isDebugModeEnabled()) {
+               // Add debug line
+               logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',indexName=' . $indexName . ',columnSql=' . $columnSql . ': does already exist.');
+       }
+}
+
 // Add ALTER TABLE `foo` CHANGE sql if not found
 function addExtensionChangeTableColumnSql ($tableName, $fromColumnName, $toColumnName, $columnSql) {
        // Is the column there?
-       if ((ifSqlColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $fromColumnName)) && (($fromColumnName == $toColumnName) || (!ifSqlColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $toColumnName)))) {
+       if ((ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $fromColumnName)) && (($fromColumnName == $toColumnName) || (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $toColumnName, isInstallationPhase())))) {
                // Then add it
                addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` CHANGE `' . $fromColumnName . '` `' . $toColumnName . '` ' . $columnSql);
        } elseif (isDebugModeEnabled()) {
@@ -2032,7 +2069,7 @@ function addExtensionChangeTableColumnSql ($tableName, $fromColumnName, $toColum
 // Add ALTER TABLE `foo` DROP sql if not found
 function addExtensionDropTableColumnSql ($tableName, $columnName) {
        // Is the column there?
-       if (ifSqlColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName)) {
+       if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $columnName, isInstallationPhase())) {
                // Then add it
                addExtensionSql('ALTER TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` DROP `' . $columnName . '`');
        } elseif (isDebugModeEnabled()) {
@@ -2041,10 +2078,22 @@ function addExtensionDropTableColumnSql ($tableName, $columnName) {
        }
 }
 
+// Add ALTER TABLE `foo` DROP INDEX sql if not found
+function addExtensionDropTableIndexSql ($tableName, $indexName) {
+       // Is the column there?
+       if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_' . $tableName, $indexName, isInstallationPhase())) {
+               // 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) {
        // Is the column there?
-       if (!ifSqlColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
+       if (!ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
                // Not found, so add it
                addExtensionAddTableColumnSql('config', $columnName, $columnSql);
        } elseif (isDebugModeEnabled()) {
@@ -2056,7 +2105,7 @@ function addConfigAddSql ($columnName, $columnSql) {
 // Drop configuration entry if found for actual extension
 function addConfigDropSql ($columnName) {
        // Is the column there?
-       if (ifSqlColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
+       if (ifSqlTableColumnExists('{?_MYSQL_PREFIX?}_config', $columnName)) {
                // Found, so add it
                addExtensionDropTableColumnSql('config', $columnName);
        } elseif (isDebugModeEnabled()) {
@@ -2202,5 +2251,19 @@ function isExtensionLibraryLoaded ($ext_name) {
        return ((isset($GLOBALS['ext_loaded']['library'][$ext_name])) && ($GLOBALS['ext_loaded']['library'][$ext_name] === TRUE));
 }
 
+// Copies the given extension's data to cache_array (USE THIS ONLY IN REGISTRATION PHASE!)
+function copyExtensionDataToCacheArray ($ext_name, $ext_id) {
+       // Copy all data
+       $GLOBALS['cache_array']['extension']['ext_id'][$currentName]         = $ext_id;
+       $GLOBALS['cache_array']['extension']['ext_name'][$ext_id]            = $currentName;
+       $GLOBALS['cache_array']['extension']['ext_version'][$currentName]    = getCurrentExtensionVersion();
+       $GLOBALS['cache_array']['extension']['ext_active'][$currentName]     = getThisExtensionAlwaysActive();
+       $GLOBALS['cache_array']['extension']['ext_lang'][$currentName]       = convertBooleanToYesNo(isExtensionLanguageFileReadable($currentName));
+       $GLOBALS['cache_array']['extension']['ext_func'][$currentName]       = convertBooleanToYesNo(isExtensionFunctionFileReadable($currentName));
+       $GLOBALS['cache_array']['extension']['ext_menu'][$currentName]       = convertBooleanToYesNo(ifModuleHasMenu($currentName));
+       $GLOBALS['cache_array']['extension']['ext_css'][$currentName]        = convertBooleanToYesNo(getExtensionHasCss());
+       $GLOBALS['cache_array']['extension']['ext_deprecated'][$currentName] = 'N';
+}
+
 // [EOF]
 ?>