X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fextensions-functions.php;h=f531cb40e88894a34561b725c8e9c6c695c09cdf;hb=16de7d9e8b98108627db01688bc095240b5ba8d2;hp=59e2e95ded0f601a09d53dabb77eed19b259741c;hpb=c2e17d983fcbc0c3bd1dd37908d87c678f0367df;p=mailer.git
diff --git a/inc/extensions-functions.php b/inc/extensions-functions.php
index 59e2e95ded..f531cb40e8 100644
--- a/inc/extensions-functions.php
+++ b/inc/extensions-functions.php
@@ -150,6 +150,9 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
// Enable dry-run
enableExtensionDryRun($dry_run);
+ // By default all extensions are in productive phase
+ enableExtensionProductive();
+
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "currName=".getCurrentExtensionName()." - ENTERED!");
// This shall never do a non-admin user or if the extension is active (already installed)
if ((!isAdmin()) || (isExtensionInstalled($ext_name))) {
@@ -236,7 +239,7 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
// 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...
+ // Extension not registered so far so first load task's id...
$task = determineExtensionTaskId($ext_update);
// Entry found?
@@ -322,6 +325,9 @@ function registerExtension ($ext_name, $task_id, $dry_run = false, $logout = tru
// Remove all SQL commands
unsetSqls();
+ // Mark it as installed
+ $GLOBALS['ext_is_installed'][getCurrentExtensionName()] = true;
+
// In normal mode return a true on success
$ret = true;
} elseif (getExtensionDryRun() === true) {
@@ -431,7 +437,10 @@ function isExtensionInstalled ($ext_name) {
$isInstalled = false;
// Check if there is a cache entry
- if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
+ if (isset($GLOBALS['ext_is_installed'][$ext_name])) {
+ // Use cache built from below queries
+ $isInstalled = $GLOBALS['ext_is_installed'][$ext_name];
+ } elseif (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
// Found!
$isInstalled = true;
@@ -441,20 +450,19 @@ function isExtensionInstalled ($ext_name) {
// Extensions are all inactive/not installed during installation
} else {
// Look in database
- $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_extensions` WHERE `ext_name`='%s' LIMIT 1",
- array($ext_name), __FILE__, __LINE__);
+ $ext_id = getExtensionId($ext_name);
// Do we have a record?
- $isInstalled = (SQL_NUMROWS($result) == 1);
+ $isInstalled = ($ext_id > 0);
// Is it installed, then cache the entry
if ($isInstalled === true) {
- // Dummy call
+ // Dummy call (get is okay here)
getExtensionId($ext_name, true);
} // END - if
- // Free result
- SQL_FREERESULT($result);
+ // Remember the status
+ $GLOBALS['ext_is_installed'][$ext_name] = $isInstalled;
}
// Return status
@@ -676,9 +684,9 @@ function addExtensionVerboseSqlTable ($title = '', $dashed = '', $switch = false
$SW = 2;
// Get all SQLs
- foreach (getExtensionSqls() as $idx => $sqls) {
+ foreach (getExtensionSqls() as $sqls) {
// New array format is recursive
- foreach ($sqls as $sql) {
+ foreach ($sqls as $idx => $sql) {
// Trim out spaces
$sql = trim($sql);
@@ -758,7 +766,7 @@ function getExtensionName ($ext_id) {
// Get extension id from name
function getExtensionId ($ext_name, $forceDb = false) {
- // Init ID number
+ // Init id number
$ret = 0;
if (isset($GLOBALS['cache_array']['extension']['ext_id'][$ext_name])) {
@@ -776,18 +784,16 @@ function getExtensionId ($ext_name, $forceDb = false) {
if (SQL_NUMROWS($result) == 1) {
// Get the extension's id from database
list($ret) = SQL_FETCHROW($result);
-
- // Cache it
- $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret;
} // END - if
// Free result
SQL_FREERESULT($result);
- }
- if ($ret == 0) {
- // We should fix these all!
- debug_report_bug(__FUNCTION__ . ': Invalid extension name found. ext_name=' . $ext_name);
+ // Cache it
+ $GLOBALS['cache_array']['extension']['ext_id'][$ext_name] = $ret;
+ } else {
+ // Caching enabled but no cache found is bad
+ debug_report_bug(__FUNCTION__ . ': Cache not found but ext-cache is active. ext_name=' . $ext_name);
} // END - if
// Return value
@@ -997,7 +1003,7 @@ function determineExtensionTaskId ($ext_name) {
// Entry found?
if (SQL_NUMROWS($result) == 1) {
- // Task found so load task's ID and register extension...
+ // Task found so load task's id and register extension...
list($task_id) = SQL_FETCHROW($result);
} // END - if
@@ -1019,7 +1025,7 @@ function determineTaskIdBySubject ($subject) {
// Entry found?
if (SQL_NUMROWS($result) == 1) {
- // Task found so load task's ID and register extension...
+ // Task found so load task's id and register extension...
list($task_id) = SQL_FETCHROW($result);
} // END - if
@@ -1036,7 +1042,7 @@ function addExtensionNotes ($ver) {
$out = ''; $content = array();
// Is do we have verbose output enabled?
- if ((getConfig('verbose_sql') == 'Y') || (!isExtensionActive('sql_patches'))) {
+ if ((!isExtensionActive('sql_patches')) || (getConfig('verbose_sql') == 'Y')) {
// Update notes found?
if (getExtensionUpdateNotes($ver) != '') {
// Update notes found
@@ -1391,9 +1397,9 @@ function FILTER_INIT_EXTENSIONS () {
// Do we have some entries?
//* DEBUG */ print __FUNCTION__.': ENTRY!
';
if (isset($GLOBALS['cache_array']['extension']['ext_name'])) {
- //* DEBUG */ print __FUNCTION__.': CACHE - START!
';
// Load all found extensions if found
- foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key=>$ext_name) {
+ //* DEBUG */ print __FUNCTION__.': CACHE - START!
';
+ foreach ($GLOBALS['cache_array']['extension']['ext_name'] as $key => $ext_name) {
// Load it
//* DEBUG */ print __FUNCTION__.': '.$ext_name.' - START
';
loadExtension($ext_name, 'init');
@@ -1708,5 +1714,17 @@ function addSponsorMenuSql ($action, $what, $title, $active, $sort) {
}
}
+// Enables/disables productive mode for current extension (used only while
+// registration).
+function enableExtensionProductive ($isProductive = true) {
+ $GLOBALS['ext_productive'][getCurrentExtensionName()] = (bool) $isProductive;
+}
+
+// Checks wether the extension is in productive phase. If not set, development
+// phase (=false) is assumed.
+function isExtensionProductive () {
+ return ((isset($GLOBALS['ext_productive'][getCurrentExtensionName()])) && ($GLOBALS['ext_productive'][getCurrentExtensionName()] === true));
+}
+
// [EOF]
?>