]> git.mxchange.org Git - mailer.git/blobdiff - inc/extensions-functions.php
Several code cleanups:
[mailer.git] / inc / extensions-functions.php
index 53619443ea04258c5da03a41596399a1f92d5847..d1c46faf4268dd058cbff96565b9b3b3cff96954 100644 (file)
@@ -179,7 +179,7 @@ function loadExtension ($ext_name, $ext_mode, $ext_ver = '0.0.0', $dry_run = fal
 }
 
 // Registers an extension and possible update dependencies
-function registerExtension ($ext_name, $taskId, $dry_run = false) {
+function registerExtension ($ext_name, $taskId, $dry_run = false, $ignoreUpdates = false) {
        // Set current extension name
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',task_id=' . $taskId . ',dry_run=' . intval($dry_run) . ' - ENTERED!');
        setCurrentExtensionName($ext_name);
@@ -197,9 +197,10 @@ function registerExtension ($ext_name, $taskId, $dry_run = false) {
        } // END - if
 
        // When this extension is already in registration/update phase, all is fine
-       if ((isExtensionRegistrationRunning($ext_name)) || (isExtensionUpdateRunning($ext_name))) {
+       if ((isExtensionRegistrationRunning($ext_name)) || ((isExtensionUpdateRunning($ext_name)) && ($ignoreUpdates === false))) {
                // Then abort here with 'true' becaus it is fine
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in registration/update phase, all fine.');
+               ///* BUG: */ debug_report_bug(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',taskId=' . $taskId . ',dry_run=' . intval($dry_run) . ' - Please investigate!');
                return true;
        } // END - if
 
@@ -239,11 +240,11 @@ function registerExtension ($ext_name, $taskId, $dry_run = false) {
 
        // Init variables
        $ret = false;
-       $test = false;
+       $processResult = false;
        initIncludePool('extension');
 
        // By default we have no failures
-       setExtensionReportsFailure(false);
+       enableExtensionReportingFailure();
 
        // Does this extension exists?
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
@@ -287,17 +288,17 @@ function registerExtension ($ext_name, $taskId, $dry_run = false) {
                                // Extension version set? If empty the extension is not registered
                                if (empty($ext_ver)) {
                                        // Extension not registered so far so first load task's id...
-                                       $task = determineExtensionTaskId($ext_update);
+                                       $taskId = determineExtensionTaskId($ext_update);
 
                                        // Entry found?
-                                       if ($task > 0) {
+                                       if ($taskId > 0) {
                                                // Try to register the extension
-                                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ':ext_update=' . $ext_update . ',taskId=' . $task);
-                                               $test = registerExtension($ext_update, $task, isExtensionDryRun(), false);
+                                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',taskId=' . $taskId . ',isExtensionDryRun()=' . isExtensionDryRun());
+                                               $processResult = registerExtension($ext_update, $taskId, isExtensionDryRun(), true);
 
                                                // Reset extension name
                                                setCurrentExtensionName($ext_name);
-                                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',test=' . intval($test));
+                                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_update=' . $ext_update . ',processResult=' . intval($processResult));
                                        } // END - if
                                } elseif ($ext_ver != getCurrentExtensionVersion()) {
                                        // Ok, update this extension now
@@ -312,14 +313,14 @@ function registerExtension ($ext_name, $taskId, $dry_run = false) {
                                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',currVer=' . getCurrentExtensionVersion());
 
                                        // All okay!
-                                       $test = true;
+                                       $processResult = true;
                                } else {
                                        // Nothing to register / update before...
-                                       $test = true;
+                                       $processResult = true;
                                }
                        } else {
                                // Required file for update does not exists!
-                               $test = true;
+                               $processResult = true;
                                // But this is fine for the first time...
                        }
 
@@ -330,19 +331,19 @@ function registerExtension ($ext_name, $taskId, $dry_run = false) {
                // Is there no update?
                if (countExtensionUpdateDependencies(getCurrentExtensionName()) == 0) {
                        // Then test is passed!
-                       $test = true;
+                       $processResult = true;
                } // END - if
 
                // Switch back to register mode
                setExtensionMode('register');
 
                // Remains true if extension registration reports no failures
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',test=' . intval($test));
-               $test = (($test === true) && (getExtensionReportsFailure() === false));
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',test=' . intval($test));
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
+               $processResult = (($processResult === true) && (isExtensionReportingFailure() === false));
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',processResult=' . intval($processResult));
 
                // Does everthing before wents ok?
-               if ($test === true) {
+               if ($processResult === true) {
                        // "Dry-run-mode" activated?
                        if ((isExtensionDryRun() === false) && (!isExtensionOnRemovalList())) {
                                // Init SQLs and transfer ext->generic
@@ -409,14 +410,14 @@ function registerExtension ($ext_name, $taskId, $dry_run = false) {
                        $ret = false;
                }
        } elseif (($taskId > 0) && (getCurrentExtensionName() != '')) {
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
                // Remove task from system when id and extension's name is valid
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
                SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `status`='NEW' LIMIT 1",
                        array(bigintval($taskId)), __FUNCTION__, __LINE__);
        }
 
        // Return status code
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',test=' . intval($test) . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ',processResult=' . intval($processResult) . ' - EXIT!');
        return $ret;
 }
 
@@ -424,7 +425,9 @@ function registerExtension ($ext_name, $taskId, $dry_run = false) {
 // @TODO Change from ext_id to ext_name (not just even the variable! ;-) )
 function doExtensionSqls ($ext_id, $load_mode) {
        // This shall never do a non-admin user!
-       if (!isAdmin()) return false;
+       if (!isAdmin()) {
+               return false;
+       } // END - if
 
        // Get extension's name
        $ext_name = getExtensionName($ext_id);
@@ -663,7 +666,7 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
        // Is this extension update already running?
        if (isExtensionUpdateRunning($ext_name)) {
                // This is fine but needs logging ATM
-               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, all fine.');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ' - already in update phase, all fine.');
                return true;
        } // END - if
 
@@ -716,10 +719,10 @@ function updateExtension ($ext_name, $ext_ver, $dry_run = false) {
                                                // Is the extension there?
                                                if (isExtensionInstalled($ext_depend)) {
                                                        // Update another extension first!
-                                                       $test = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun());
+                                                       $processResult = updateExtension($ext_depend, getExtensionVersion($ext_depend), isExtensionDryRun());
                                                } else {
                                                        // Register new extension
-                                                       $test = registerExtension($ext_depend, 0, isExtensionDryRun(), false);
+                                                       $processResult = registerExtension($ext_depend, 0, isExtensionDryRun());
                                                }
                                        } // END - if
                                } // END - foreach
@@ -1017,7 +1020,7 @@ function createNewExtensionTask ($ext_name) {
        // Not installed and do we have created a task for the admin?
        if (($taskId == '0') && (!isExtensionInstalled($ext_name))) {
                // Set default message if ext-foo is missing
-               $message = getMaskedMessage('ADMIN_EXTENSION_TEXT_FILE_MISSING', $ext_name);
+               $message = '{%message,ADMIN_EXTENSION_TEXT_FILE_MISSING=' . $ext_name . '%}';
 
                // Template file
                $FQFN = sprintf("%stemplates/%s/html/ext/ext_%s.tpl",
@@ -1305,6 +1308,7 @@ function isExtensionUpdateDependenciesInitialized () {
 // Checks wether an update is already running for given extension
 function isExtensionUpdateRunning ($ext_name) {
        // Current and given extensions means whole array
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ' - ENTERED!');
        if ($ext_name == getCurrentExtensionName()) {
                // Default is not found
                $isRunning = false;
@@ -1316,13 +1320,13 @@ function isExtensionUpdateRunning ($ext_name) {
                        if (($ext1 == $ext_name) || (in_array($ext_name, $depends))) {
                                // Found
                                $isRunning = true;
-                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=' . intval($isRunning));
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext1=' . $ext1 . ',ext_name=' . $ext_name . ',isRunning=' . intval($isRunning) . ' - ADDED!');
                                break;
                        } // END - if
                } // END - foreach
 
                // Return result
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ', isRunning=' . intval($isRunning) . ' - EXIT!');
                return $isRunning;
        } // END - if
 
@@ -1330,7 +1334,7 @@ function isExtensionUpdateRunning ($ext_name) {
        $isRunning = ((isExtensionUpdateDependenciesInitialized()) && (in_array($ext_name, getExtensionRunningUpdates())));
 
        // Return it
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ', isRunning=' . intval($isRunning));
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currentExtension=' . getCurrentExtensionName() . ',ext_name=' . $ext_name . ', isRunning=' . intval($isRunning) . ' - EXIT!');
        return $isRunning;
 }
 
@@ -1345,19 +1349,19 @@ function initExtensionRuningUpdates () {
 
 // Getter for EXT_UPDATE_DEPENDS flag
 function getExtensionUpdateDependencies () {
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
        return $GLOBALS['ext_update_depends'][getCurrentExtensionName()];
 }
 
 // Getter for next iterator depency
 function getExtensionUpdateDependenciesIterator () {
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
        return ($GLOBALS['ext_update_depends'][getCurrentExtensionName()][getExtensionUpdateIterator()]);
 }
 
 // Counter for extension update depencies
 function countExtensionUpdateDependencies () {
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
        return count($GLOBALS['ext_update_depends'][getCurrentExtensionName()]);
 }
 
@@ -1378,7 +1382,7 @@ function removeExtensionDependency ($ext_name) {
 
 // Init iterator for update depencies
 function initExtensionUpdateIterator () {
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
        $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()] = '0';
 }
 
@@ -1388,23 +1392,23 @@ function getExtensionUpdateIterator () {
        if (!isset($GLOBALS['ext_depend_iterator'][getCurrentExtensionName()])) initExtensionUpdateIterator();
 
        // Return it
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName().'/'.$GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]);
        return $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()];
 }
 
 // Increments the update iterator
 function incrementExtensionUpdateIterator () {
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName());
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'currName=' . getCurrentExtensionName());
        $GLOBALS['ext_depend_iterator'][getCurrentExtensionName()]++;
 }
 
 // Setter for EXT_REPORTS_FAILURE flag
-function setExtensionReportsFailure ($reportsFailure) {
+function enableExtensionReportingFailure ($reportsFailure = false) {
        $GLOBALS['ext_reports_failure'] = (bool) $reportsFailure;
 }
 
 // Getter for EXT_REPORTS_FAILURE flag
-function getExtensionReportsFailure () {
+function isExtensionReportingFailure () {
        return $GLOBALS['ext_reports_failure'];
 }
 
@@ -1752,11 +1756,16 @@ function isExtensionFunctionFileReadable ($ext_name) {
 }
 
 // Adds a CREATE TABLE statement if the requested table is not there
-function addCreateTableSql ($tableName, $sql) {
+function addCreateTableSql ($tableName, $sql, $comment) {
        // Is the table not there?
        if (!isSqlTableCreated($tableName)) {
                // Is not found, so add it
-               addExtensionSql('CREATE TABLE `{?_MYSQL_PREFIX?}_' . $tableName . '` ' . $sql);
+               addExtensionSql('CREATE TABLE
+       `{?_MYSQL_PREFIX?}_' . $tableName . '` (' . $sql . ')
+ENGINE = {?_TABLE_TYPE?}
+CHARACTER SET utf8
+COLLATE utf8_general_ci
+COMMENT ' . "'" . $comment . "'");
        } else {
                // Is already there, which should not happen
                debug_report_bug(__FUNCTION__, __LINE__, 'The table ' . $tableName . ' is already created which should not happen.');
@@ -1809,27 +1818,23 @@ function addAdminMenuSql ($action, $what, $title, $descr, $sort) {
 }
 
 // Adds a guest menu to the SQL queue if the menu entry is not found
-function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
+function addGuestMenuSql ($action, $what, $title, $sort) {
        // Now check if this menu is there
        if (!isMenuActionValid('guest', $action, $what)) {
                // Is what null?
                if (is_null($what)) {
                        // Add main menu
-                       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
+                       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','N','Y',%s)",
                                $action,
                                $title,
-                               $visible,
-                               $locked,
                                bigintval($sort)
                        );
                } else {
                        // Add sub menu
-                       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
+                       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','N','Y',%s)",
                                $action,
                                $what,
                                $title,
-                               $visible,
-                               $locked,
                                bigintval($sort)
                        );
                }
@@ -1843,27 +1848,23 @@ function addGuestMenuSql ($action, $what, $title, $visible, $locked, $sort) {
 }
 
 // Adds a member menu to the SQL queue if the menu entry is not found
-function addMemberMenuSql ($action, $what, $title, $visible, $locked, $sort) {
+function addMemberMenuSql ($action, $what, $title, $sort) {
        // Now check if this menu is there
        if (!isMenuActionValid('member', $action, $what)) {
                // Is what null?
                if (is_null($what)) {
                        // Add main menu
-                       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','%s','%s',%s)",
+                       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s',NULL,'%s','N','Y',%s)",
                                $action,
                                $title,
-                               $visible,
-                               $locked,
                                bigintval($sort)
                        );
                } else {
                        // Add sub menu
-                       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','%s','%s',%s)",
+                       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_member_menu` (`action`,`what`,`title`,`visible`,`locked`,`sort`) VALUES('%s','%s','%s','N','Y',%s)",
                                $action,
                                $what,
                                $title,
-                               $visible,
-                               $locked,
                                bigintval($sort)
                        );
                }