| 1 | #! /usr/bin/env php |
| 2 | <?php |
| 3 | // |
| 4 | // $Id: setdebug.php 36 2010-06-02 08:35:47Z dapob $ |
| 5 | // $HeadURL: file:///var/svn/misc/trunk/magento/scripts/setdebug.php $ |
| 6 | // |
| 7 | // Copyright (C) 2009 Damien Pobel <dpobel@free.fr> |
| 8 | // |
| 9 | // This program is free software: you can redistribute it and/or modify |
| 10 | // it under the terms of the GNU General Public License as published by |
| 11 | // the Free Software Foundation, either version 3 of the License, or |
| 12 | // (at your option) any later version. |
| 13 | // |
| 14 | // This program is distributed in the hope that it will be useful, |
| 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | // GNU General Public License for more details. |
| 18 | // |
| 19 | // You should have received a copy of the GNU General Public License |
| 20 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | // |
| 22 | |
| 23 | |
| 24 | require 'app/Mage.php'; |
| 25 | if (!Mage::isInstalled()) { |
| 26 | echo "Application is not installed yet, please complete install wizard first."; |
| 27 | exit; |
| 28 | } |
| 29 | Mage::app(); |
| 30 | |
| 31 | define('WRONG_OPTION_CODE', 1); |
| 32 | define('EXCEPTION_CODE', 2); |
| 33 | |
| 34 | $_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']); |
| 35 | $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']); |
| 36 | |
| 37 | $templateHints = null; |
| 38 | $templateHintsBlock = null; |
| 39 | $profiler = null; |
| 40 | $codeWebsite = ''; |
| 41 | |
| 42 | $webSites = Mage::app()->getWebsites(true, true); |
| 43 | $existingWebSiteCodes = implode(', ', array_keys($webSites)); |
| 44 | |
| 45 | $optionsArray = array('help|h' => 'Display this message', |
| 46 | 'site|s=s' => 'Code of the site where option should be changed, should be one of the following : ' . $existingWebSiteCodes, |
| 47 | 'hints|i' => 'Enables "Template path hints" option', |
| 48 | 'block|b' => 'Enables "Add Block Names to Hints" option (implies -i option)', |
| 49 | 'profiler|p' => 'Enables "Profiler" option', |
| 50 | 'disable|d' => 'Disable "Template path hints", "Add Block Name to Hints" and "Profiler" options'); |
| 51 | |
| 52 | try { |
| 53 | $opts = new Zend_Console_Getopt($optionsArray); |
| 54 | $opts->parse(); |
| 55 | } catch(Exception $e) { |
| 56 | echo "Exception " . $e->getMessage() . PHP_EOL; |
| 57 | exit(EXCEPTION_CODE); |
| 58 | } |
| 59 | |
| 60 | if (isset($opts->h)) { |
| 61 | echo $opts->getUsageMessage(); |
| 62 | exit(); |
| 63 | } |
| 64 | |
| 65 | if (isset($opts->s)) { |
| 66 | $codeWebsite = $opts->s; |
| 67 | } else { |
| 68 | echo $opts->getUsageMessage(); |
| 69 | exit(WRONG_OPTION_CODE); |
| 70 | } |
| 71 | |
| 72 | if (isset($opts->d)) { |
| 73 | $templateHints = 0; |
| 74 | $templateHintsBlock = 0; |
| 75 | $profiler = 0; |
| 76 | } elseif (isset($opts->b)) { |
| 77 | $templateHints = 1; |
| 78 | $templateHintsBlock = 1; |
| 79 | } |
| 80 | |
| 81 | if (isset($opts->i)) { |
| 82 | $templateHints = 1; |
| 83 | } |
| 84 | |
| 85 | if (isset($opts->p)) { |
| 86 | $profiler = 1; |
| 87 | } |
| 88 | |
| 89 | try { |
| 90 | $website = Mage::getModel('core/website'); |
| 91 | $website->load($codeWebsite); |
| 92 | if ($website->getId() === null) { |
| 93 | echo "Error : \"" . $codeWebsite . "\" website does not exist" . PHP_EOL; |
| 94 | echo $opts->getUsageMessage(); |
| 95 | exit(WRONG_OPTION_CODE); |
| 96 | } |
| 97 | $config = Mage::getConfig(); |
| 98 | if ($templateHints !== null) { |
| 99 | $config->saveConfig('dev/debug/template_hints', $templateHints, 'websites', $website->getId()); |
| 100 | } |
| 101 | if ($templateHintsBlock !== null) { |
| 102 | $config->saveConfig('dev/debug/template_hints_blocks', $templateHintsBlock, 'websites', $website->getId()); |
| 103 | } |
| 104 | if ($profiler !== null) { |
| 105 | $config->saveConfig('dev/debug/profiler', $profiler, 'websites', $website->getId()); |
| 106 | } |
| 107 | } catch (Exception $e) { |
| 108 | echo "Exception " . $e->getMessage(); |
| 109 | exit(EXCEPTION_CODE); |
| 110 | } |
| 111 | |
| 112 | |