/** * 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(); } } }
/** * Converts a Google Sitemap XML file to a CSV File. * * @param string $options * @return void * @author Nicholas Vahalik <*****@*****.**> */ public function xmlsm2csvAction($options) { $settings['path-only'] = Wiz::getWiz()->getArg('path-only'); $filename = array_shift($options); switch (strtolower(substr($filename, -3))) { case 'xml': $xml = simplexml_load_file($filename); if ($xml->getName() != 'urlset') { throw new Exception('This does not look like an XML sitemap.'); } $output = fopen('php://temp', 'rw'); foreach ($xml->url as $node) { if ($settings['path-only']) { $pathinfo = parse_url((string) $node->loc); $url = $pathinfo['path']; } else { $url = (string) $node->loc; } fputcsv($output, array($url)); } rewind($output); while ($stuff = fgets($output, 1024)) { echo $stuff; } break; default: throw new Exception('Invalid file format.'); } }
/** * Replace the standard 3 spaces asXml products with whatever we want. * * @param string $matches * @return void * @author Nicholas Vahalik <*****@*****.**> */ protected function _replaceSpaces($matches) { $newSpaces = (int) Wiz::getWiz()->getArg('indent'); return str_repeat(' ', strlen($matches[1]) / 3 * $newSpaces); }
/** * Resets an admin user's password. If you do not pass the parameters, * you will be prompted for them. * * Options: * --send-email Will send the user an e-mail about their new * password. * * --random Will generate a random password. * * --show Will show the password saved to the user. * * @param Username (optional) * @param Password (optional) * @author Nicholas Vahalik <*****@*****.**> */ function resetpassAction($options) { $username = $password = ''; foreach ($options as $option) { if (strpos(trim($option), '--') !== 0) { $realParams[] = $option; } } // Load up what we have. switch (count($realParams)) { case 2: $password = array_pop($realParams); case 1: $username = array_pop($realParams); default: } // Asks for what we don't have. while ($username == '') { printf('Login: '******'' && !Wiz::getWiz()->getArg('random')) { printf('New Password: '******'random')) { $password = Mage::helper('core')->getRandomString(10); } $adminUser = Mage::getModel('admin/user')->loadByUsername($username); if (!$adminUser->getId()) { throw new Exception(sprintf('Unable to find user "%s"', $username)); } $adminUser->setPassword($password)->save(); if (Wiz::getWiz()->getArg('send-email')) { $adminUser->setPlainPassword($password); $adminUser->sendNewPasswordEmail(); } if (Wiz::getWiz()->getArg('show')) { printf('Password for user "%s" has been changed to "%s".' . PHP_EOL, $username, $password); } else { printf('Password for user "%s" has been updated.' . PHP_EOL, $username); } }
<?php /** * Wiz * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * http://opensource.org/licenses/osl-3.0.php * * DISCLAIMER * * This program is provided to you AS-IS. There is no warranty. It has not been * certified for any particular purpose. * * @package Wiz * @author Nick Vahalik <*****@*****.**> * @copyright Copyright (c) 2012 Classy Llama Studios, LLC * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ include 'app/Wiz.php'; $wiz = Wiz::getWiz(); $wiz->run();
public static function batchOutput($table) { $format = Wiz::getWiz()->getArg('batch'); if (!is_array($table) || count($table) < 1 || !is_array($table[0])) { $table = array(array('Result' => 'No Data')); } $keys = array_keys($table[0]); $delimiter = $enclosure = '"'; array_unshift($table, $keys); switch ($format) { case 'csv': default: $delimiter = ','; $enclosure = '"'; // Quickly put everything break; case 'pipe': $delimiter = '|'; break; case 'tab': $delimiter = "\t"; break; } // We use some memory here to quickly create a CSV file. $csv = fopen('php://temp/maxmemory:' . 5 * 1024 * 1024, 'r+'); foreach ($table as $row) { fputcsv($csv, $row, $delimiter, $enclosure); } rewind($csv); $output = stream_get_contents($csv); return $output; }
/** * Returns a list of model names to class maps. This will also call out rewritten * classes so you can see what type of object you will get when you call * Mage::getModel(_something_). * * +------------+-------------------+ * | Model Name | PHP Class | * +------------+-------------------+ * | varien/* | Varien_* | * | core/* | Mage_Core_Model_* | * | ... | | * +------------+-------------------+ * * Options: * --all (shows everything, default) * --models (shows only models, not resource models) * --resources (shows only resource models, not models) * * @author Nicholas Vahalik <*****@*****.**> **/ public function modelsAction() { Wiz::getMagento(); $modelMapping = array(); $config = Mage::getConfig(); $showModels = Wiz::getWiz()->getArg('models'); $showResources = Wiz::getWiz()->getArg('resources'); if (Wiz::getWiz()->getArg('all') || !$showModels && !$showResources) { $showResources = $showModels = true; } foreach ($config->getNode('global/models')->children() as $parent => $children) { if (substr($parent, -7) == '_mysql4' && !$showResources || substr($parent, -7) != '_mysql4' && !$showModels) { continue; } foreach ($children->children() as $className => $classData) { switch ($className) { case 'class': $modelMapping[] = array('Model Name' => $parent . '/*', 'PHP Class' => (string) $classData . '_*'); break; case 'rewrite': foreach ($classData->children() as $rewriteName => $rewriteData) { $modelMapping[] = array('Model Name' => $parent . '/' . $rewriteName, 'PHP Class' => (string) $rewriteData); } default: break; } } } echo Wiz::tableOutput($modelMapping); }