Esempio n. 1
0
File: Wiz.php Progetto: nvahalik/Wiz
 /**
  * Instantiates and sets up Magento.  By default, use the admin scopeCode so we run
  * inside of the administration context.
  *
  * @param string $scopeCode 
  * @param string $scopeId 
  * @return Mage_Core_Model_App
  * @author Nicholas Vahalik <*****@*****.**>
  */
 public static function getMagento($scopeCode = 'admin', $scopeId = 'store')
 {
     /**
      * Our local copy of the Magento Application Object
      * 
      * @see Mage_Core_Model_App
      */
     static $_magento;
     if (!$_magento) {
         // Did we get a directory from an environment variable?
         $wizMagentoRoot = Wiz::getMagentoRoot();
         // No dice. :-(
         if ($wizMagentoRoot === FALSE) {
             die('Please specify a Magento root directory by setting WIZ_MAGE_ROOT.' . PHP_EOL);
         }
         chdir($wizMagentoRoot);
         /**
          * Attempt to bootstrap Magento.
          */
         $compilerConfig = 'includes/config.php';
         if (file_exists($compilerConfig)) {
             include $compilerConfig;
         }
         require 'app/Mage.php';
         umask(0);
         // If someone passes a scope code via he CLI, then use that.
         foreach (array('store', 'website') as $scope) {
             if (($argScopeCode = Wiz::getWiz()->getArg($scope)) !== FALSE) {
                 // If --store is specified, but not provided, use the default.
                 $scopeCode = $argScopeCode === TRUE ? '' : $argScopeCode;
                 $scopeId = $scope;
                 break;
             }
         }
         // We only want to enable profiling if it has been turned on within the
         // configuration AND if the --profile argument was passed into the command.
         if (Mage::getStoreConfig('dev/debug/profiler') && Wiz::getWiz()->getArg('profile')) {
             Varien_Profiler::enable();
         }
         $_magento = Mage::app($scopeCode, $scopeId);
     }
     return $_magento;
 }
Esempio n. 2
0
 /**
  * Removes the maintenance flag, allowing Magento to run.
  *
  * @author Nicholas Vahalik <*****@*****.**>
  */
 function startAction()
 {
     if (($magentoRoot = Wiz::getMagentoRoot()) === FALSE) {
         throw new Exception('Unable to find Magento.');
     }
     $maintenanceFile = $magentoRoot . WIZ_DS . 'maintenance.flag';
     if (!file_exists($maintenanceFile)) {
         echo 'Maintenance file does not exist.' . PHP_EOL;
         return;
     }
     if (!is_writable($maintenanceFile)) {
         throw new Exception('Cannot remove maintenance flag file.  Is the directory writable?');
     }
     unlink($maintenanceFile);
     echo 'Magento maintenance flag has been removed.' . PHP_EOL;
 }
Esempio n. 3
0
 /**
  * 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);
 }