From fc7eb4dd5875e23845bcd15ebebf46b6760a5380 Mon Sep 17 00:00:00 2001 From: Josh Walker Date: Mon, 14 Sep 2015 16:31:32 -0700 Subject: [PATCH 1/3] #123 Backend checks now use drupal_set_message() and output more specific messages. --- includes/config.inc | 39 -------------- includes/utils.inc | 121 ++++++++++++++++++++++++++++++++++++++++---- theme-settings.php | 2 +- 3 files changed, 113 insertions(+), 49 deletions(-) diff --git a/includes/config.inc b/includes/config.inc index dcead1d..8deba10 100644 --- a/includes/config.inc +++ b/includes/config.inc @@ -71,45 +71,6 @@ function kalatheme_bootstrap_library_form() { return $form; } -/** - * Form constructor for Bootstrap library selection form - * - * @return array - */ -function kalatheme_backend_check_form() { - $form = array(); - - if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) { - $form['pantheon_check'] = array( - '#weight' => -100, - '#prefix' => '
', - '#markup' => t("You are on Pantheon. You need to set the connection mode to SFTP to allow for custom Bootstrap libraries and subtheme generation!"), - '#suffix' => '
', - ); - } - else { - if (kalatheme_backend_check()) { - $form['backend_check'] = array( - '#weight' => -100, - '#prefix' => '
', - '#markup' => t("Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!"), - '#suffix' => '
', - ); - } - else { - $form['backend_check'] = array( - '#weight' => -100, - '#prefix' => '
', - '#markup' => t("If you want Kalatheme to be able to use custom Bootstrap libraries or generate subthemes automatically please properly configure your webserver."), - // @todo add link to docs here - '#suffix' => '
', - ); - } - } - - return $form; -} - /** * Form constructor for subtheme selection form * diff --git a/includes/utils.inc b/includes/utils.inc index 802b538..10b60da 100644 --- a/includes/utils.inc +++ b/includes/utils.inc @@ -316,18 +316,121 @@ function kalatheme_use_libraries() { * True if all good, message if no good */ function kalatheme_backend_check() { - // Verify FTP support - $ftp_installed = extension_loaded('ftp'); - // Verify SSH support - $ssh_installed = extension_loaded('ssh2'); - // Verify web server write permissions - $install_permissions = kalatheme_has_write_access(); - // Verify update module is enabled - $updates_module = module_exists('update'); + $info = kalatheme_backend_check_info(); + $messages = drupal_get_messages(NULL, FALSE); - return (($ftp_installed || $ssh_installed || $install_permissions) && $updates_module); + // Output messages for each of the checks. + foreach ($info as $check) { + if (isset($check['messages']) && !empty($check['messages'])) { + $bool = $check['bool']; + if (isset($check['messages'][$bool])) { + $message = $check['messages'][$bool]; + $status = $check['bool'] ? 'status' : 'error'; + + // Make sure we don't set a message twice. + $already_set = FALSE; + foreach ($messages[$status] as $existing) { + if ($existing == $message) { + $already_set = TRUE; + break; + } + } + + if (!$already_set) { + drupal_set_message($message, $status); + } + } + } + } + + return ($info['install_permissions'] && $info['updates_module']); +} + +/** + * Store and return info about backend features that we might need for Kalatheme + * to work properly. + */ +function kalatheme_backend_check_info(){ + $info = array( + // Check if we're on Pantheon. + 'pantheon' => array( + 'bool' => isset($_SERVER['PANTHEON_ENVIRONMENT']), + 'messages' => array( + TRUE => t('You are on Pantheon. !strong_openYou need to set the connection mode to SFTP!strong_close to allow for custom Bootstrap libraries and subtheme generation!', array('!strong_open' => '', '!strong_close' => '')), + ), + ), + // Verify FTP support + 'ftp' => array( + 'bool' => extension_loaded('ftp'), + 'messages' => array(), + ), + // Verify SSH support + 'ssh' => array( + 'bool' => extension_loaded('ssh2'), + 'messages' => array(), + ), + // Verify web server write permissions + 'write_access' => array( + 'bool' => kalatheme_has_write_access(), + 'messages' => array( + FALSE => t('Your webserver permissions are not configured correctly to facilitate subtheme generation. See !the_wiki for help.', array('!the_wiki' => l('the wiki', 'https://github.com/drupalprojects/kalatheme/wiki/Configuring-Server-for-Automatic-Kalatheme-installation'))), + ), + ), + // Verify update module is enabled + 'updates_module' => array( + 'bool' => module_exists('update'), + 'messages' => array( + FALSE => t('The Updates module needs be enabled for subtheme generation. Please visit the !modules_page to enable it.', array('!modules_page' => l('modules page', 'admin/modules'))), + ), + ), + ); + + // This one is a conglomerate of some of the others. + $info['install_permissions'] = array( + 'bool' => $info['ftp']['bool'] || $info['ssh']['bool'] || $info['write_access']['bool'], + 'messages' => array( + TRUE => t('Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!'), + FALSE => t('Kalatheme need FTP, SSH or write access in order to generate a subtheme.'), + ), + ); + + return $info; } + +if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) { + $form['pantheon_check'] = array( + '#weight' => -100, + '#prefix' => '
', + '#markup' => t("You are on Pantheon. You need to set the connection mode to SFTP to allow for custom Bootstrap libraries and subtheme generation!"), + '#suffix' => '
', + ); + } + else { + if (kalatheme_backend_check()) { + $form['backend_check'] = array( + '#weight' => -100, + '#prefix' => '
', + '#markup' => t("Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!"), + '#suffix' => '
', + ); + } + else { + $form['backend_check'] = array( + '#weight' => -100, + '#prefix' => '
', + '#markup' => t("If you want Kalatheme to be able to use custom Bootstrap libraries or generate subthemes automatically please properly configure your webserver."), + // @todo add link to docs here + '#suffix' => '
', + ); + } + } + + + + + + /** * Check whether Kalatheme has write access to libraries and modules directories. * diff --git a/theme-settings.php b/theme-settings.php index b5b7301..661166b 100644 --- a/theme-settings.php +++ b/theme-settings.php @@ -32,7 +32,7 @@ function kalatheme_form_system_theme_settings_alter(&$form, &$form_state) { } // Subtheme backend checks - $form = array_merge($form, kalatheme_backend_check_form()); + kalatheme_backend_check(); // Kalatheme settings $form = array_merge($form, kalatheme_bootstrap_library_form()); From 7f0c9f1fcdc3d9b7de007c029514569060c4b69f Mon Sep 17 00:00:00 2001 From: Josh Walker Date: Mon, 18 Apr 2016 17:30:49 -0700 Subject: [PATCH 2/3] #123: Getting rid of errors when things don't exist and also removing old code outside of function. --- includes/utils.inc | 56 ++++++++++------------------------------------ 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/includes/utils.inc b/includes/utils.inc index 10b60da..6c4c28b 100644 --- a/includes/utils.inc +++ b/includes/utils.inc @@ -326,29 +326,31 @@ function kalatheme_backend_check() { if (isset($check['messages'][$bool])) { $message = $check['messages'][$bool]; $status = $check['bool'] ? 'status' : 'error'; - + // Make sure we don't set a message twice. $already_set = FALSE; - foreach ($messages[$status] as $existing) { - if ($existing == $message) { - $already_set = TRUE; - break; + if (isset($messages[$status])) { + foreach ($messages[$status] as $existing) { + if ($existing == $message) { + $already_set = TRUE; + break; + } } } - + if (!$already_set) { drupal_set_message($message, $status); } } } } - + return ($info['install_permissions'] && $info['updates_module']); } /** * Store and return info about backend features that we might need for Kalatheme - * to work properly. + * to work properly. */ function kalatheme_backend_check_info(){ $info = array( @@ -384,7 +386,7 @@ function kalatheme_backend_check_info(){ ), ), ); - + // This one is a conglomerate of some of the others. $info['install_permissions'] = array( 'bool' => $info['ftp']['bool'] || $info['ssh']['bool'] || $info['write_access']['bool'], @@ -393,44 +395,10 @@ function kalatheme_backend_check_info(){ FALSE => t('Kalatheme need FTP, SSH or write access in order to generate a subtheme.'), ), ); - + return $info; } - -if (isset($_SERVER['PANTHEON_ENVIRONMENT'])) { - $form['pantheon_check'] = array( - '#weight' => -100, - '#prefix' => '
', - '#markup' => t("You are on Pantheon. You need to set the connection mode to SFTP to allow for custom Bootstrap libraries and subtheme generation!"), - '#suffix' => '
', - ); - } - else { - if (kalatheme_backend_check()) { - $form['backend_check'] = array( - '#weight' => -100, - '#prefix' => '
', - '#markup' => t("Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!"), - '#suffix' => '
', - ); - } - else { - $form['backend_check'] = array( - '#weight' => -100, - '#prefix' => '
', - '#markup' => t("If you want Kalatheme to be able to use custom Bootstrap libraries or generate subthemes automatically please properly configure your webserver."), - // @todo add link to docs here - '#suffix' => '
', - ); - } - } - - - - - - /** * Check whether Kalatheme has write access to libraries and modules directories. * From 22f56cdb089eb321b61155bd55eb04f58a6bff43 Mon Sep 17 00:00:00 2001 From: Josh Walker Date: Wed, 11 May 2016 13:27:21 -0700 Subject: [PATCH 3/3] #123: more work --- includes/utils.inc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/includes/utils.inc b/includes/utils.inc index 911288e..2887ee2 100644 --- a/includes/utils.inc +++ b/includes/utils.inc @@ -320,12 +320,13 @@ function kalatheme_backend_check() { $messages = drupal_get_messages(NULL, FALSE); // Output messages for each of the checks. - foreach ($info as $check) { + foreach ($info as $type => $check) { if (isset($check['messages']) && !empty($check['messages'])) { $bool = $check['bool']; if (isset($check['messages'][$bool])) { $message = $check['messages'][$bool]; $status = $check['bool'] ? 'status' : 'error'; + $status = $type == 'pantheon' ? 'warning' : $status; // Make sure we don't set a message twice. $already_set = FALSE; @@ -345,7 +346,7 @@ function kalatheme_backend_check() { } } - return ($info['install_permissions'] && $info['updates_module']); + return ($info['install_permissions']['bool'] && $info['updates_module']['bool']); } /** @@ -387,14 +388,17 @@ function kalatheme_backend_check_info(){ ), ); - // This one is a conglomerate of some of the others. - $info['install_permissions'] = array( - 'bool' => $info['ftp']['bool'] || $info['ssh']['bool'] || $info['write_access']['bool'], - 'messages' => array( - TRUE => t('Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!'), - FALSE => t('Kalatheme need FTP, SSH or write access in order to generate a subtheme.'), - ), - ); + $info['install_permissions'] = array('bool' => TRUE); + if (!isset($_SERVER['PANTHEON_ENVIRONMENT'])) { + // This one is a conglomerate of some of the others. + $info['install_permissions'] = array( + 'bool' => $info['ftp']['bool'] || $info['ssh']['bool'] || $info['write_access']['bool'], + 'messages' => array( + TRUE => t('Your webserver is correctly configured to allow for custom Bootstrap libraries and subtheme generation!'), + FALSE => t('Kalatheme needs FTP, SSH or write access in order to generate a subtheme.'), + ), + ); + } return $info; } @@ -402,7 +406,7 @@ function kalatheme_backend_check_info(){ /** * Check whether Kalatheme has write access to libraries and modules directories. * - * This check indicates whether we have enough access to be able to use + * This check indicates whether we have enough access to be able to use * authorize.php and the updater. * * @return boolean