Example #1
0
 /**
  * @magentoAppIsolation enabled
  */
 public function testReset()
 {
     Mage::setRoot(dirname(__FILE__));
     $this->assertNotNull(Mage::getRoot());
     Mage::reset();
     $this->assertNull(Mage::getRoot());
 }
Example #2
0
File: Xtest.php Project: nhp/Xtest
 protected static function init($code)
 {
     Mage::$headersSentThrowsException = false;
     $options = array();
     $options['config_model'] = 'Codex_Xtest_Model_Core_Config';
     $options['cache_dir'] = Mage::getBaseDir('var') . DS . 'cache' . DS . 'xtest';
     Mage::reset();
     Mage::app($code, 'store', $options);
     if ($disableDouble = (bool) self::getArg('disable_double', false)) {
         self::getConfig()->setDisableDoubles($disableDouble);
     }
 }
Example #3
0
 public function tearDown()
 {
     parent::tearDown();
     // reset $_POST
     Mage::app()->getRequest()->setPost(array());
     // close connections
     Mage::getSingleton('core/resource')->getConnection(Mage_Core_Model_Resource_Setup::DEFAULT_SETUP_CONNECTION)->closeConnection();
     // reset session
     if (session_id()) {
         session_destroy();
     }
     // reset Magento
     Mage::reset();
 }
Example #4
0
 /**
  * Method download choosen page by url in argument and retrieves
  * its contents.
  * @param string $url
  * @return string contents of downloaded page
  */
 function downloadPage($url)
 {
     if ($this->isReady()) {
         /* remember Magento state and reset Magento */
         $prevURI = $_SERVER['REQUEST_URI'];
         $state = Mage::getStaticState();
         Mage::reset();
         /* start catching output */
         ob_start();
         /* run new Magento */
         $_SERVER['REQUEST_URI'] = preg_replace('/http(s){0,1}:\\/\\/[^\\/]*/', '', $url);
         Mage::run();
         /* get output */
         $html = ob_get_contents();
         /* end catching output */
         ob_end_clean();
         /* restore Magento state */
         Mage::restoreState($state);
         return $html;
     }
     return '';
 }
 /**
  * @test
  * @author Luke Rodgers <*****@*****.**>
  */
 public function reinitMissingCacheEntry()
 {
     /**
      * Initialise Mage and warm the cache
      */
     Mage::app();
     Mage::reset();
     /**
      * Get a copy of the admin configuration from the warmed up cache
      */
     $before = Mage::app()->getCacheInstance()->load('config_global_stores');
     $before = new Varien_Simplexml_Element($before);
     $before = $before->descend('admin')->asXML();
     /**
      * Initialise Mage and remove config_global from the cache, to simulate hitting a fake cache lock
      */
     Mage::reset();
     Mage::app()->getCacheInstance()->remove('config_global');
     /**
      * Recall init, which calls Mage_Core_Model_Config:;init,
      * useCache is still true, but we have the hit the fake cache lock on config_global.
      */
     Mage::app()->init(Mage_Core_Model_App::ADMIN_STORE_ID, 'store');
     /**
      * Get a copy of the admin configuration from the corrupted cache
      */
     Mage::reset();
     $after = Mage::app()->getCacheInstance()->load('config_global_stores');
     $after = new Varien_Simplexml_Element($after);
     $after = $after->descend('admin')->asXML();
     $this->assertEquals($before, $after);
 }
Example #6
0
 /**
  * Reset application global state
  */
 public function resetApp()
 {
     /** @var $objectManager Magento_Test_ObjectManager */
     $objectManager = Mage::getObjectManager();
     $objectManager->clearCache();
     $resource = Mage::registry('_singleton/Mage_Core_Model_Resource');
     Mage::reset();
     Varien_Data_Form::setElementRenderer(null);
     Varien_Data_Form::setFieldsetRenderer(null);
     Varien_Data_Form::setFieldsetElementRenderer(null);
     if ($resource) {
         Mage::register('_singleton/Mage_Core_Model_Resource', $resource);
     }
 }
Example #7
0
 /**
  * Clean the application, so next time it will load itself again (i.e. after uninstall)
  *
  * @return Magento_Application
  */
 protected function _cleanupMage()
 {
     Mage::reset();
     return $this;
 }
Mage::reset();
if (!Mage::app()->useCache('config')) {
    die("Config cache needs to be enabled.");
}
/**
 * Clearing every bit of cache I can get a hold of, to simulate an empty cache to begin with
 */
Mage::app()->getCacheInstance()->clean();
Mage::app()->getCacheInstance()->flush();
Mage::app()->getCache()->clean();
Mage::reset();
/**
 * Warming up the cache.
 */
Mage::app();
Mage::reset();
/**
 * Initialise mage app,
 * sets useCache = true
 *
 * Removes config_global to simulate a time sensitive cache hit on the config_global.lock cache entry
 */
Mage::app()->getCacheInstance()->remove('config_global');
/**
 * Recall init, which calls Mage_Core_Model_Config:;init,
 * useCache is still true, but we have the hit the fake cache lock on config_global.
 */
Mage::app()->init(Mage_Core_Model_App::ADMIN_STORE_ID, 'store');
/**
 * Reload a non FPC page, you should see a 100 router match iteration page / no 404 page
 */
Example #9
0
 public function run()
 {
     // Set tracking
     $track = $this->getArgs('t', 'track');
     if ($track !== false) {
         if (!strcmp('0', $track)) {
             $doTracking = $this->_helper->disable();
         } else {
             $doTracking = $this->_helper->enable();
         }
     } else {
         $doTracking = $this->_helper->isActive();
     }
     // Set username
     $user = $this->getArgs('u', 'user');
     if ($user !== false) {
         $this->_helper->setUser($user);
     }
     if ($this->getArgs('s', 'status')) {
         $this->_printHeader();
         $pendingList = $this->_io->getPendingList();
         if (count($pendingList)) {
             printf("Pending Actions list:\r\n");
             foreach ($pendingList as $i => $row) {
                 $actionDescr = sprintf("ID: %d\t - %s (%s on %s)", $i + 1, $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_DESCR], $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_USER], strftime("%c", $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_TIMESTAMP]));
                 $spacer = str_repeat(" ", max(0, 40 - strlen($actionDescr)));
                 printf("%s\r\n", $actionDescr);
             }
             printf("\r\nTotal pending actions: %d\r\n", count($pendingList));
         } else {
             printf("There aren't any pending actions to execute.\r\n");
         }
     } else {
         if ($limit = $this->getArgs('hi', 'history')) {
             $this->_printHeader();
             $historyList = $this->_io->getHistoryList($limit);
             if (count($historyList)) {
                 printf("Global Actions list:\r\n");
                 foreach ($historyList as $i => $row) {
                     $actionDescr = sprintf("ID: %d\t - %s (%s on %s)", $i + 1, $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_DESCR], $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_USER], strftime("%c", $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_TIMESTAMP]));
                     $spacer = str_repeat(" ", max(0, 40 - strlen($actionDescr)));
                     printf("%s\r\n", $actionDescr);
                 }
                 printf("\r\nTotal global actions listed: %d\r\n", count($historyList));
             } else {
                 printf("There aren't any actions tracked.\r\n");
             }
         } else {
             if ($id = $this->getArgs('r', 'run')) {
                 $this->_printHeader();
                 $pendingList = $this->_io->getPendingList();
                 if (count($pendingList)) {
                     $executed = 0;
                     $session = Mage::getSingleton('adminhtml/session');
                     foreach ($pendingList as $i => $row) {
                         if ($id > 0 && $i + 1 != $id) {
                             continue;
                         }
                         $actionExecutorClass = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_EXECUTOR_CLASS];
                         $actionExecutorVersion = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_VERSION];
                         $controllerModule = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_CONTROLLER_MODULE];
                         $controllerName = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_CONTROLLER_NAME];
                         $controllerClassName = $this->_getControllerClassName($controllerModule, $controllerName);
                         if (class_exists($actionExecutorClass)) {
                             $controllerFileName = $this->_getControllerClassPath($controllerModule, $controllerName);
                             if (file_exists($controllerFileName)) {
                                 include_once $controllerFileName;
                             } else {
                                 printf("Error: file '%s' not found!\r\n", $controllerFileName);
                             }
                             if (class_exists($controllerClassName)) {
                                 $actionExecutor = new $actionExecutorClass();
                                 $parameters = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_PARAMS];
                                 try {
                                     $request = $actionExecutor->decode($parameters, $actionExecutorVersion);
                                     $controller = new $controllerClassName($request, new PugMoRe_Mageploy_Controller_Response_Http());
                                     $action = $row[PugMoRe_Mageploy_Model_Action_Abstract::INDEX_ACTION_NAME] . 'Action';
                                     $controller->preDispatch();
                                     $controller->{$action}();
                                     $controller->postDispatch();
                                 } catch (Zend_Controller_Response_Exception $e) {
                                     # do nothing: avoid "Headers already sent" error message
                                 } catch (Exception $e) {
                                     $session->addError($e->getMessage());
                                 }
                                 // Add messages in body response in case of Ajax requests
                                 $messages = $session->getMessages(true);
                                 if ($request && $request->getParam('isAjax', false)) {
                                     $body = $controller->getResponse()->getBody();
                                     $msg = Mage::getSingleton('core/message')->notice($body);
                                     $messages->add($msg);
                                 }
                                 foreach ($messages->getItems() as $message) {
                                     $messageType = $message->getType();
                                     switch ($messageType) {
                                         case Mage_Core_Model_Message::ERROR:
                                             $color = self::TERM_COLOR_RED;
                                             break;
                                         case Mage_Core_Model_Message::SUCCESS:
                                             $color = self::TERM_COLOR_GREEN;
                                             break;
                                         default:
                                             #break intentionally omitted
                                         #break intentionally omitted
                                         case Mage_Core_Model_Message::WARNING:
                                             #break intentionally omitted
                                         #break intentionally omitted
                                         case Mage_Core_Model_Message::NOTICE:
                                             $color = self::TERM_COLOR_YELLOW;
                                             break;
                                     }
                                     printf("Action ID #%d - %s %s\r\n", $i + 1, $this->__getColoredString($message->getType(), $color), $message->getText());
                                 }
                                 $executed++;
                                 // register executed action
                                 $this->_io->done($row);
                             } else {
                                 printf("Error: class '%s' not found!\r\n", $controllerClassName);
                             }
                         } else {
                             printf("Error: class '%s' not found!\r\n", $actionExecutorClass);
                         }
                         // Yes, PHP is Object Oriented but don't forget the
                         // Superglobals! After all PHP is not Java :-)
                         $_GET = array();
                         $_POST = array();
                         $_REQUEST = array();
                         // And don't forget to reinitialize Magento to avoid
                         // problems with already populated objects (i.e. registry)
                         Mage::reset();
                         Mage::init($this->_appCode, $this->_appType);
                     }
                     // end foreach
                     printf("\r\nExecuted actions: %d/%d\r\n", $executed, count($pendingList));
                 } else {
                     printf("There aren't any pending actions to execute.\r\n");
                 }
             } else {
                 echo $this->usageHelp($doTracking);
             }
         }
     }
     printf("\r\n");
 }
 /**
  * Runs the WebApplication
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance
  *
  * @return string The web applications content
  */
 public function run(HttpServletRequestInterface $servletRequest)
 {
     try {
         // register the Magento autoloader as FIRST autoloader
         spl_autoload_register(array(new \Varien_Autoload(), 'autoload'), true, true);
         // Varien_Profiler::enable();
         if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
             \Mage::setIsDeveloperMode(true);
         }
         ini_set('display_errors', 1);
         umask(0);
         // store or website code
         $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
         // run store or run website
         $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
         // set headers sent to false and start output caching
         appserver_set_headers_sent(false);
         ob_start();
         // reset and run Magento
         \Mage::reset();
         \Mage::register('ServletRequest', $servletRequest);
         \Mage::run();
         // write the session back after the request
         session_write_close();
         // We need to init the session anew, so PHP session handling will work like it would in a clean environment
         appserver_session_init();
         // grab the contents generated by Magento
         $content = ob_get_clean();
     } catch (\Exception $e) {
         error_log($content = $e->__toString());
     }
     // return the content
     return $content;
 }
Example #11
0
 /**
  * @magentoAppIsolation enabled
  */
 public function testReset()
 {
     Mage::setIsDeveloperMode(true);
     $this->assertTrue(Mage::getIsDeveloperMode());
     Mage::reset();
     $this->assertFalse(Mage::getIsDeveloperMode());
 }
Example #12
0
 /**
  * clean up runtime details
  */
 protected function _cleanUpProcess()
 {
     Mage::reset();
     Mage::app('admin', 'store');
     $entityCode = $this->getEntityTypeCode();
     $this->_entityTypeId = Mage::getSingleton('eav/config')->getEntityType($entityCode)->getEntityTypeId();
     $this->_connection = Mage::getSingleton('core/resource')->getConnection('write');
 }
Example #13
0
 /**
  * Initialize an already installed Magento application
  *
  * @param string $scopeCode
  * @param string $scopeType
  */
 public function initialize($scopeCode = '', $scopeType = 'store')
 {
     if (!class_exists('Mage', false)) {
         require_once $this->_magentoDir . '/app/bootstrap.php';
     } else {
         $resource = Mage::registry('_singleton/Mage_Core_Model_Resource');
         Mage::reset();
         if ($resource) {
             Mage::register('_singleton/Mage_Core_Model_Resource', $resource);
         }
     }
     $this->_options = array('etc_dir' => $this->_installEtcDir, 'var_dir' => $this->_installDir, 'tmp_dir' => $this->_installDir . DIRECTORY_SEPARATOR . 'tmp', 'cache_dir' => $this->_installDir . DIRECTORY_SEPARATOR . 'cache', 'log_dir' => $this->_installDir . DIRECTORY_SEPARATOR . 'log', 'session_dir' => $this->_installDir . DIRECTORY_SEPARATOR . 'session', 'media_dir' => $this->_installDir . DIRECTORY_SEPARATOR . 'media', 'upload_dir' => $this->_installDir . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . 'upload');
     Mage::setIsDeveloperMode($this->_developerMode);
     Mage::app($scopeCode, $scopeType, $this->_options);
 }
Example #14
0
 /**
  * Reset application global state
  */
 protected function _resetApp()
 {
     /** @var $layout Mage_Core_Model_Layout */
     $layout = Mage::registry('_singleton/Mage_Core_Model_Layout');
     if ($layout) {
         /* Force to cleanup circular references */
         $layout->__destruct();
     }
     Mage::reset();
     Varien_Data_Form::setElementRenderer(null);
     Varien_Data_Form::setFieldsetRenderer(null);
     Varien_Data_Form::setFieldsetElementRenderer(null);
 }
Example #15
0
 public function saveOrder($code, $products)
 {
     $customer = $this->getCustomer($code);
     $orderData = $this->orderDefaults;
     if (!count($customer->getData())) {
         return false;
     }
     $orderData['session']['customer_id'] = $customer->getId();
     $orderData['session']['store_id'] = $this->getStoreId();
     $session = $this->getSessionModel();
     $session->setCustomerId($customer->getId());
     $session->setStoreId($this->getStoreId());
     $orderData['order']['account']['email'] = $customer->getEmail();
     $billingAddressId = $customer->getDefaultBilling();
     $shippingAddressId = $customer->getDefaultShipping();
     $orderData['order']['billing_address'] = $this->getAddress($billingAddressId);
     $orderData['order']['shipping_address'] = $this->getAddress($shippingAddressId);
     $orderData['add_products'] = $products;
     $order = $this->getOrderModel();
     \Mage::unregister('config');
     \Mage::reset();
     \Mage::app();
     if (count($order->getQuote()->getAllItems())) {
         $quote = $order->getQuote();
         $items = $quote->getAllItems();
         foreach ($items as $item) {
             $quote->removeItem($item->getItemId());
         }
         $quote->save();
         $order->setQuote($quote);
     }
     \Mage::unregister('config');
     \Mage::reset();
     \Mage::app();
     $order->importPostData($orderData['order']);
     \Mage::unregister('rule_data');
     $addedProducts = false;
     foreach ($orderData['add_products'] as $sku => $_data) {
         $price = $_data['price'];
         unset($_data['price']);
         $product = $this->getProductBySku($sku);
         if (!$product) {
             continue;
         }
         $order->getQuote()->addProduct($product, new \Varien_Object(['qty' => $_data['qty']]))->setOriginalCustomPrice($price);
         $addedProducts = true;
     }
     if (!$addedProducts) {
         return false;
     }
     $order->collectShippingRates();
     $order->getQuote()->getPayment()->addData($orderData['payment']);
     $order->initRuleData()->saveQuote();
     $order->setPaymentData($orderData['payment']);
     $order->getQuote()->getPayment()->addData($orderData['payment']);
     \Mage::app()->getStore()->setConfig(\Mage_Sales_Model_Order::XML_PATH_EMAIL_ENABLED, "0");
     $increment_id = false;
     try {
         $increment_id = $order->importPostData($orderData['order'])->createOrder()->getIncrementId();
     } catch (Exception $e) {
         print_r($e);
     }
     \Mage::unregister('config');
     \Mage::reset();
     \Mage::app();
     if (count($order->getQuote()->getAllItems())) {
         $quote = $order->getQuote();
         $items = $quote->getAllItems();
         foreach ($items as $item) {
             $quote->removeItem($item->getItemId());
         }
         $quote->save();
         $order->setQuote($quote);
     }
     \Mage::unregister('config');
     \Mage::reset();
     \Mage::app();
     return $increment_id;
 }
 /**
  * Runs the WebApplication
  *
  * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $servletRequest The request instance
  *
  * @return string The web applications content
  */
 public function run(HttpServletRequestInterface $servletRequest)
 {
     try {
         // register the Magento autoloader as FIRST autoloader
         spl_autoload_register(array(new \Varien_Autoload(), 'autoload'), true, true);
         // Varien_Profiler::enable();
         if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
             \Mage::setIsDeveloperMode(true);
         }
         ini_set('display_errors', 1);
         umask(0);
         // store or website code
         $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
         // run store or run website
         $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
         // set headers sent to false and start output caching
         appserver_set_headers_sent(false);
         ob_start();
         // reset and run Magento
         \Mage::reset();
         \Mage::register(MageStandardSessionServlet::SERVLET_REQUEST, $servletRequest);
         \Mage::run();
         /*
         // load the session and persist the data from $_SESSION
         $session = $servletRequest->getSession();
         
         foreach ($_SESSION as $namespace => $data) {
             if ($namespace !== 'identifier') {
                 error_log("Now add data for session {$session->getId()} and namespace: ". PHP_EOL . var_export($dat));
                 $session->putData($namespace, $data);
             }
         }
         */
         // grab the contents generated by Magento
         $content = ob_get_clean();
     } catch (\Exception $e) {
         error_log($content = $e->__toString());
     }
     // return the content
     return $content;
 }