/** * Executes PHP file after bootstrapping Magento. * * You can optionally specify the store under which to execute the script by passing * --store <storecode>. * * You can optionally specify to display Varien_Profiler data by passing --profile. * * @param filename * @author Nicholas Vahalik <*****@*****.**> */ function scriptAction($options) { if (count($options) < 1) { echo 'Please enter a script to execute.' . PHP_EOL; return FALSE; } elseif (!is_readable($options[0])) { echo 'Please enter a valid filename to execute.' . PHP_EOL; return FALSE; } else { $path = realpath($options[0]); Wiz::getMagento(); // We have to check the settings AFTER we bootstrap Magento so that we can use the Mage class. if (Wiz::getWiz()->getArg('profile')) { if (!Mage::getStoreConfig('dev/debug/profiler') || !Mage::helper('core')->isDevAllowed()) { echo 'Please turn on the Varien_Profiler by executing the "devel-profiler yes" command' . PHP_EOL; return FALSE; } else { $profiling = true; } } include $path; if ($profiling) { $this->_flushProfileData(); } } }
/** * Generates htaccess 301 redirects for the current magento site. Output is written * to stdout. * * Usage: wiz 301-htgen <csv_file> * * CSV File will be a two-column CSV file in the following format: * /old/path/to/product1.html,SKU1 * /old/path/to/product2.html,SKU2 * * @param URL to SKU CSV File. * @return void * @author Nicholas Vahalik <*****@*****.**> */ function htgenAction($options) { $filename = realpath($options[0]); if (!file_exists($filename)) { throw new Exception('Need a file to generate 301 mappings.'); } else { file_put_contents('php://stderr', 'Reading current mappings from ' . $filename . PHP_EOL); } Wiz::getMagento('store'); $file_contents = file_get_contents($filename); $lines = explode(PHP_EOL, $file_contents); $redirectFormat = 'redirect 301 %s %s' . PHP_EOL; $output = $errors = ''; $model = Mage::getModel('catalog/product'); $baseUrl = Mage::getBaseUrl(); $done = 0; foreach ($lines as $line) { $done++; list($url, $sku) = explode(', ', $line); $sku = strtoupper(trim($sku)); $productId = $model->getIdBySku($sku); if ($productId === FALSE) { $errors .= 'Product not found for SKU# ' . $sku . PHP_EOL; } $product = Mage::getModel('catalog/product')->load($productId); $output .= sprintf($redirectFormat, $url, str_replace($baseUrl, '/', $product->getProductUrl())); } echo $output . PHP_EOL; file_put_contents('php://stderr', 'Mapped ' . $done . ' records.' . PHP_EOL); if ($errors != '') { $errors = '========================================' . PHP_EOL . '== Errors ==' . PHP_EOL . '========================================' . PHP_EOL . $errors . PHP_EOL; file_put_contents('php://stderr', $errors); } }
private function _getDbConfig($config = 'core') { Wiz::getMagento(); $resources = Mage::getSingleton('core/resource'); $connection = $resources->getConnection('core'); $config = $connection->getConfig(); return $config; }
/** * Lists all of the stores, store codes, and websites on the magento installation. * * @author Nicholas Vahalik <*****@*****.**> */ public static function listAction() { Wiz::getMagento(); $storeCollection = Mage::getModel('core/store')->getCollection(); foreach ($storeCollection as $store) { $rows[] = array('Website (Id)' => $store->getWebsite()->getCode() . ' (' . $store->getWebsiteId() . ')' . ($store->getWebsite()->getIsDefault() ? ' default' : ''), 'Group (Id)' => $store->getGroup()->getName() . ' (' . $store->getGroup()->getId() . ')', 'Code (Id)' => $store->getName() . ' (' . $store->getCode() . ')', 'Active' => $store->getIsActive()); } echo Wiz::tableOutput($rows); }
/** * Runs the cron. * * @author Nicholas Vahalik <*****@*****.**> */ public function runAction($options) { Wiz::getMagento(); Mage::app('admin')->setUseSessionInUrl(false); try { Mage::getConfig()->init()->loadEventObservers('crontab'); Mage::app()->addEventArea('crontab'); Mage::dispatchEvent('default'); } catch (Exception $e) { throw $e; } }
/** * Returns the entire Magento config as nicely formatted XML to stdout. * Options: * --ugly (optional) Makes the output ugly (no tabs or newlines) * * --system Returns the modules configuration (system.xml) * * --indent <int> Number of spaces to use to indent the XML. The * default is 3. * * @return The Magento Configuration as as nicely printed XML File. * @author Nicholas Vahalik <*****@*****.**> */ public function asxmlAction() { Wiz::getMagento(); if (Wiz::getWiz()->getArg('system')) { $xml = Mage::getConfig()->loadModulesConfiguration('system.xml'); } else { $xml = Mage::getConfig(); } if (!Wiz::getWiz()->getArg('ugly')) { $output = $xml->getNode()->asNiceXml(''); // Update with our indentation if so desired. if (Wiz::getWiz()->getArg('indent') !== false) { $output = preg_replace_callback('#^(\\s+)#m', array($this, '_replaceSpaces'), $output); } } else { $output = $xml->getNode()->asXml(); } echo $output; echo PHP_EOL; }
/** * Displays a full list of resources that are defined by modules in Magento. * * @param string $options * @return void * @author Nicholas Vahalik <*****@*****.**> */ public function resourcesAction($options) { $formattedOutput = $output = array(); Wiz::getMagento(); $aclResources = Mage::getModel('admin/config')->getAdminhtmlConfig()->getNode("acl/resources"); $output = $this->_recurseXmlWalkResources($aclResources->admin); foreach ($output as $data) { $formattedOutput[] = array('Path' => $data[0], 'Title' => $data[1]); } usort($formattedOutput, array($this, '_sortAclEntries')); echo Wiz::tableOutput($formattedOutput); }
/** * Disables output for a module. This performs the same task as the Disable Module * Output page in the Magento backend. * * @author Nicholas Vahalik <*****@*****.**> */ public static function disableoutputAction($options) { if (count($options) < 1) { echo 'Please provide modules names to enable.' . PHP_EOL; } $modulesDisable = $modulesAlreadyDisabled = array(); Wiz::getMagento(); $modules = (array) Mage::getConfig()->getNode('modules')->children(); foreach ($options as $moduleName) { foreach ($modules as $systemModuleName => $moduleData) { if (strtolower($moduleName) == strtolower($systemModuleName)) { $flag = strtolower(Mage::getConfig()->getNode('advanced/modules_disable_output/' . $systemModuleName, 'default')); if (empty($flag) || 'false' === $flag) { Mage::getConfig()->saveConfig('advanced/modules_disable_output/' . $systemModuleName, TRUE); // self::changeModuleOutput($systemModuleName, 'disabled'); $modulesDisabled[] = $systemModuleName; } else { $modulesAlreadyDisabled[] = $systemModuleName; } break; } } } if (count($modulesDisabled) > 0) { echo 'Module(s) disabled: ' . implode(', ', $modulesDisabled) . PHP_EOL; Mage::getConfig()->removeCache(); } if (count($modulesAlreadyDisabled)) { echo 'Module(s) already disabled: ' . implode(', ', $modulesAlreadyDisabled) . PHP_EOL; } }
/** * Cleans Magento's database logs. Uses Magento's global settings. * * Adapted from the log.php that ships with Magento. * * @author Nicholas Vahalik <*****@*****.**> */ public function cleanAction() { Wiz::getMagento(''); $this->_getLog()->clean(); $savedDays = Mage::getStoreConfig(Mage_Log_Model_Log::XML_LOG_CLEAN_DAYS); echo "Log cleaned. Log days saved: {$savedDays}" . PHP_EOL; }
/** * Changes the status of the indexing processes to "Manual". * If no processes are specified, all processes will be set. * * @param processes to index * @author Nicholas Vahalik <*****@*****.**> */ public function manualAction($options) { Wiz::getMagento(); $processes = $this->_parseIndexerString(count($options) == 0 ? 'all' : implode(',', $options)); $updated = $this->_setMode($processes, Mage_Index_Model_Process::MODE_MANUAL); echo 'Index' . (count($updated) > 1 ? 'es' : '') . ' set to Manual: ' . implode(', ', $updated) . PHP_EOL; }
/** * Attempts to output a list of dispatched Magento Events. Currently, it iterates * recursively over the app/ directory and looks for instances where Mage::dispatchEvent * is called. It then outputs the first parameter as the "event." Some events have * variables inside of them (like EAV product events and some controller events). * * @return void * @author Nicholas Vahalik <*****@*****.**> */ public function eventsAction() { Wiz::getMagento(); $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(Wiz::getMagentoRoot() . DIRECTORY_SEPARATOR . 'app')); foreach ($iterator as $file) { if (preg_match('#.php$#', $file->getFilename())) { $phpFiles[] = $file->getRealpath(); } } $baseClasses = get_declared_classes(); foreach ($phpFiles as $fileName) { $matches = array(); include $fileName; // echo get_include_path().PHP_EOL; $extraClasses = get_declared_classes(); // var_dump(array_diff($extraClasses, $baseClasses)); $fileSource = file_get_contents($fileName); preg_match_all('#Mage::dispatchEvent\\((.*)\\);#m', $fileSource, $matches); if (count($matches) > 1 && count($matches[1]) > 1) { foreach ($matches[1] as $match) { if (strpos($match, ',') !== FALSE) { $stuff = explode(',', $match); $eventName = trim($stuff[0]); } else { $eventName = $match; } if (substr($stuff[0], 0, 1) == "'" || substr($stuff[0], 0, 1) == '"') { $eventName = substr(trim($stuff[0]), 1, -1); } $events[] = $eventName; } } } $events = array_unique($events); sort($events); foreach ($events as $eventName) { $eventOutput[] = array('Event Name' => $eventName); } echo Wiz::tableOutput($eventOutput); }