]> git.mxchange.org Git - mailer.git/blobdiff - inc/ajax/ajax_installer.php
AJAX installation is 'basicly finished' :) Plus I threw in a small christmas present...
[mailer.git] / inc / ajax / ajax_installer.php
index ecdc4bdebb5ef2d6214a35ab6f0a8000ff9a09bb..1fedf138f03ac6fb463ccae4ab03854486501340 100644 (file)
@@ -65,7 +65,7 @@ function establishAjaxInstallerDatabaseLink () {
        if (!SQL_SELECT_DB(getSession('mysql_dbase'), __FUNCTION__, __LINE__)) {
                // Could not be selected
                reportBug(__FUNCTION__, __LINE__, 'Could not select database ' . getSession('mysql_dbase'));
-       } elseif ((!isFileReadable(getPath() . 'install/tables.sql')) || (!isFileReadable(getPath() . 'install/menu-'.getLanguage().'.sql'))) {
+       } elseif ((!isFileReadable(getSession('base_path') . 'install/tables.sql')) || (!isFileReadable(getSession('base_path') . 'install/menu-'.getLanguage().'.sql'))) {
                // Installation area not found
                reportBug(__FUNCTION__, __LINE__, 'SQL dumps not found. Please extract ALL files from the archive or checkout all files out from SVN.');
        } elseif (ifFatalErrorsDetected()) {
@@ -139,6 +139,7 @@ function doAjaxInstallerFooterNavigation () {
                case 'database_config':
                case 'smtp_config':
                case 'other_config':
+               case 'extensions':
                        array_push($enabledNavigations, 'previous');
                case 'welcome': // Only 'next' works for welcome page
                        array_push($enabledNavigations, 'next');
@@ -225,7 +226,7 @@ function doAjaxInstallerRequestContent () {
                        setHttpStatus('200 OK');
                } else {
                        // Set 404 error
-                       setHttpStatus('404 NOT FOUND');
+                       setHttpStatus('404 Not Found');
                }
        } // END - if
 }
@@ -241,8 +242,14 @@ function doAjaxInstallerChangeWarning () {
        // "Walk" through all elements
        $OUT = '<ol>';
        foreach (explode(':', postRequestElement('elements')) as $element) {
-               // Add row
-               $OUT .= '<li>{--INSTALLER_CHANGED_ELEMENT_' . strtoupper($element) . '--}</li>';
+               // Is it an extension?
+               if (substr($element, 0, 4) == 'ext_') {
+                       // Add row for extension
+                       $OUT .= '<li>{%message=INSTALLER_CHANGED_ELEMENT_EXTENSION=' . str_replace('_', '-', $element) . '%}</li>';
+               } else {
+                       // Add generic row
+                       $OUT .= '<li>{--INSTALLER_CHANGED_ELEMENT_' . strtoupper($element) . '--}</li>';
+               }
        } // END - foreach
        $OUT .= '</ol>';
 
@@ -277,7 +284,7 @@ function doAjaxInstallerSaveChanges () {
        $currentTab = postRequestElement('tab');
 
        // Remove some elements which should not be saved
-       foreach (array('do', 'level') as $removedElement) {
+       foreach (array('tab', 'do', 'level') as $removedElement) {
                // Remove this element from POST data
                unsetPostRequestElement($removedElement);
        } // END - foreach
@@ -297,6 +304,7 @@ function doAjaxInstallerSaveChanges () {
        // Now set all remaining data in session
        foreach (postRequestArray() as $key => $value) {
                // Set it, if it is valid, else it will be added to $saveStatus (call-by-reference)
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value[' . gettype($value) . '=' . $value);
                $saveStatus['is_saved'] = (
                        // Is the data valid?
                        (isInstallerDataValid($saveStatus, $key, $value))
@@ -307,7 +315,7 @@ function doAjaxInstallerSaveChanges () {
 
                // Save the overall status for below final check
                $isAllSaved = (($isAllSaved === TRUE) && ($saveStatus['is_saved'] === TRUE));
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',is_saved=' . intval($saveStatus['is_saved']) . ',isAllSaved=' . intval($isAllSaved));
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value[' . gettype($value) . '=' . $value . ',is_saved=' . intval($saveStatus['is_saved']) . ',isAllSaved=' . intval($isAllSaved));
        } // END - foreach
 
        // 'is_saved' is still true?
@@ -446,6 +454,21 @@ function doAjaxPrepareInstallerOtherConfig () {
        } // END - if
 }
 
+// Prepare AJAX request 'extensions'
+function doAjaxPrepareInstallerExtensions () {
+       // Is 'extensions' set?
+       if (!isSessionVariableSet('extensions')) {
+               /*
+                * At least ext-sql_patches and ext-task should be installed
+                *(ext-sql_patches is a must!)
+                */
+               setSession('extensions', 'admins:sql_patches:task');
+       } elseif (strpos(getSession('extensions'), 'sql_patches') === FALSE) {
+               // Add missing ext-sql_patches
+               setSession('extensions', getSession('extensions') . ':sql_patches');
+       }
+}
+
 // Prepare AJAX request 'overview'
 function doAjaxPrepareInstallerOverview () {
        // 'tab' must always be set to create a post-check-callback
@@ -548,6 +571,100 @@ function doAjaxInstallerStepImportTablesSql () {
 
        // Now run all queries through
        runFilterChain('run_sqls');
+
+       // Close SQL link
+       SQL_CLOSE(__FUNCTION__, __LINE__);
+}
+
+// Call-back function to import menu SQL file
+function doAjaxInstallerStepImportMenuSql () {
+       // Establish database link
+       establishAjaxInstallerDatabaseLink();
+
+       // Init SQL array
+       initSqls();
+
+       // Import tables.sql
+       importInstallSqlDump('menu-' . getLanguage());
+
+       // Are some SQLs found?
+       if (countSqls() == 0) {
+               // Abort here
+               reportBug(__FUNCTION__, __LINE__, '{--INSTALLER_SQL_IMPORT_FAILED--}');
+       } // END - if
+
+       // Now run all queries through
+       runFilterChain('run_sqls');
+
+       // Close SQL link
+       SQL_CLOSE(__FUNCTION__, __LINE__);
+}
+
+// Call-back function to install some important extensions
+function doAjaxInstallerStepInstallExtensions () {
+       // Only one element is required
+       if (!isSessionVariableSet('extensions')) {
+               // Some required session data is not set
+               reportBug(__FUNCTION__, __LINE__, 'Required session data for this step not found.');
+       } // END - if
+
+       // Establish database link
+       establishAjaxInstallerDatabaseLink();
+
+       // Get all extensions
+       $extensions = explode(':', getSession('extensions'));
+
+       // Make sure ext-sql_patches is first
+       array_unshift($extensions, 'sql_patches');
+
+       // "Walk" through all extensions
+       foreach ($extensions as $key => $ext_name) {
+               // Is ext-sql_patches not at key=0?
+               if (($key == 0) && ($ext_name == 'sql_patches')) {
+                       // Then skip this entry
+                       continue;
+               } elseif ((!loadExtension($ext_name, 'test', '0.0.0', TRUE)) || (!registerExtension($ext_name, NULL))) {
+                       // Didn't work
+                       reportBug(__FUNCTION__, __LINE__, 'Cannot load/register extension ' . $ext_name . '.');
+               } // END - if
+       } // END - foreach
+
+       // Close SQL link
+       SQL_CLOSE(__FUNCTION__, __LINE__);
+}
+
+// Call-back function to write local configuration file
+function doAjaxInstallerStepWriteLocalConfig () {
+       // Is all set?
+       if (!isSessionDataSet(array('base_path', 'base_url', 'main_title', 'slogan', 'webmaster', 'mysql_host', 'mysql_dbase', 'mysql_prefix', 'mysql_login', 'mysql_password1', 'mysql_password2', 'mysql_engine', 'output_mode', 'warn_no_pass', 'write_footer', 'enable_backlink'))) {
+               // Some required session data is not set
+               reportBug(__FUNCTION__, __LINE__, 'Required session data for this step not found.');
+       } // END - if
+
+       // Write config file
+       if (!doInstallWriteLocalConfigurationFile(
+               getSession('base_path'),
+               getSession('base_url'),
+               getSession('main_title'),
+               getSession('slogan'),
+               getSession('webmaster'),
+               getSession('warn_no_pass'),
+               getSession('write_footer'),
+               getSession('enable_backlink'),
+               getSession('mysql_host'),
+               getSession('mysql_dbase'),
+               getSession('mysql_login'),
+               getSession('mysql_password1'),
+               getSession('mysql_prefix'),
+               getSession('mysql_engine'),
+               getSession('smtp_host'),
+               getSession('smtp_user'),
+               getSession('smtp_password1')
+       )) {
+               // Something bad went wrong
+               removeFile(getSession('base_path') . getCachePath() . 'config-local.php');
+               reportBug(__FUNCTION__, __LINE__, 'Did not fully write config-local.php .');
+       }
 }
 
 // [EOF]