Example #1
0
 public function setUp()
 {
     Mage::setIsDeveloperMode(false);
     Mage::getConfig()->setNode('default/dev/log/file', 'phpunit.system.log');
     $this->mockAdminUserSession();
     parent::setUp();
 }
 /**
  * Set developer mode if applicable
  */
 public function __construct()
 {
     if (self::isDev()) {
         Mage::setIsDeveloperMode(true);
         ini_set('display_errors', 1);
     }
 }
Example #3
0
 protected function tearDown()
 {
     ini_set('display_errors', $this->_oldDisplayErrors);
     error_reporting($this->_oldErrorLevel);
     Mage::setIsDeveloperMode($this->_oldIsDeveloperMode);
     unset($this->_block);
 }
Example #4
0
 /**
  * Send all messages in a queue
  *
  * @return Mage_Core_Model_Email_Queue
  */
 public function send()
 {
     /** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
     $collection = Mage::getModel('core/email_queue')->getCollection()->addOnlyForSendingFilter()->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)->setCurPage(1)->load();
     ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
     ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
     /** @var $message Mage_Core_Model_Email_Queue */
     foreach ($collection as $message) {
         if ($message->getId()) {
             $parameters = new Varien_Object($message->getMessageParameters());
             if ($parameters->getReturnPathEmail() !== null) {
                 $mailTransport = new Zend_Mail_Transport_Sendmail("-f" . $parameters->getReturnPathEmail());
                 Zend_Mail::setDefaultTransport($mailTransport);
             }
             $mailer = new Zend_Mail('utf-8');
             foreach ($message->getRecipients() as $recipient) {
                 list($email, $name, $type) = $recipient;
                 switch ($type) {
                     case self::EMAIL_TYPE_BCC:
                         $mailer->addBcc($email, '=?utf-8?B?' . base64_encode($name) . '?=');
                         break;
                     case self::EMAIL_TYPE_TO:
                     case self::EMAIL_TYPE_CC:
                     default:
                         $mailer->addTo($email, '=?utf-8?B?' . base64_encode($name) . '?=');
                         break;
                 }
             }
             if ($parameters->getIsPlain()) {
                 $mailer->setBodyText($message->getMessageBody());
             } else {
                 $mailer->setBodyHTML($message->getMessageBody());
             }
             $mailer->setSubject('=?utf-8?B?' . base64_encode($parameters->getSubject()) . '?=');
             $mailer->setFrom($parameters->getFromEmail(), $parameters->getFromName());
             if ($parameters->getReplyTo() !== null) {
                 $mailer->setReplyTo($parameters->getReplyTo());
             }
             if ($parameters->getReturnTo() !== null) {
                 $mailer->setReturnPath($parameters->getReturnTo());
             }
             try {
                 //$mailer->send();
                 $mailer->send(Mage::helper('smtp')->getTransport());
                 unset($mailer);
                 $message->setProcessedAt(Varien_Date::formatDate(true));
                 $message->save();
             } catch (Exception $e) {
                 unset($mailer);
                 $oldDevMode = Mage::getIsDeveloperMode();
                 Mage::setIsDeveloperMode(true);
                 Mage::logException($e);
                 Mage::setIsDeveloperMode($oldDevMode);
                 return false;
             }
         }
     }
     return $this;
 }
 public function __construct($magentoPath)
 {
     require_once $magentoPath . 'app/Mage.php';
     \Mage::setIsDeveloperMode(true);
     $this->websiteId = \Mage::app()->getWebsite()->getId();
     $this->storeId = \Mage::app()->getStore()->getId();
     return $this;
 }
Example #6
0
 /**
  * Test that getConfig method retrieve Varien_Object object
  */
 public function testGetConfig()
 {
     // we have to set strict error reporting mode and enable mage developer mode to convert notice to exception
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', 1);
     Mage::setIsDeveloperMode(true);
     $this->assertInstanceOf('Varien_Object', $this->_block->getConfig());
 }
Example #7
0
 /**
  * Test that there is no notice in _saveValueTitles()
  *
  * @covers Mage_Catalog_Model_Resource_Product_Option_Value::_saveValueTitles
  */
 public function testSaveValueTitles()
 {
     $object = new Stub_UnitTest_Mage_Catalog_Model_Resource_Product_Option_Value_Mage_Core_Model_Stub(self::$valueTitleData);
     // we have to set strict error reporting mode and enable mage developer mode to convert notice to exception
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', 1);
     Mage::setIsDeveloperMode(true);
     $this->_object->saveValueTitles($object);
 }
Example #8
0
 /**
  * Test that there is no notice in _updateDataWithCategoryColumns()
  *
  * @covers Mage_ImportExport_Model_Export_Entity_Product::_updateDataWithCategoryColumns
  *
  * @magentoDataFixture Mage/ImportExport/_files/product.php
  */
 public function testExport()
 {
     // we have to set strict error reporting mode and enable mage developer mode to convert notice to exception
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', 1);
     Mage::setIsDeveloperMode(true);
     $this->_model->setWriter(Mage::getModel('Mage_ImportExport_Model_Export_Adapter_Csv'));
     $this->assertNotEmpty($this->_model->export());
 }
Example #9
0
 public function __construct()
 {
     parent::__construct();
     Mage::setIsDeveloperMode(true);
     //always enable developer mode when run through the shell.
     if ($this->getArg('profiler') == '1') {
         Varien_Profiler::enable();
     }
 }
Example #10
0
 /**
  * Test that there is no notice in _updateDataWithCategoryColumns()
  *
  * @covers Mage_ImportExport_Model_Export_Entity_Product::_updateDataWithCategoryColumns
  */
 public function testUpdateDataWithCategoryColumnsNoCategoriesAssigned()
 {
     $dataRow = array();
     $productId = 1;
     $rowCategories = array($productId => array());
     // we have to set strict error reporting mode and enable mage developer mode to convert notice to exception
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', 1);
     Mage::setIsDeveloperMode(true);
     $this->assertTrue($this->_object->updateDataWithCategoryColumns($dataRow, $rowCategories, $productId));
 }
Example #11
0
 /**
  * undocumented function
  *
  * @return void
  * @author Alistair Stead
  **/
 protected function _bootstrap()
 {
     //load Magento
     $mageFilename = 'app/Mage.php';
     $this->_isInstalled($mageFilename);
     require_once $mageFilename;
     Mage::setIsDeveloperMode(true);
     Mage::app();
     // get request/response object
     $this->_request = $this->_registry->getRequest();
     $this->_response = $this->_registry->getResponse();
 }
Example #12
0
 /**
  * Handle the initial setup, including profiling and bootstrapping the
  * Magento environment
  *
  * @return void
  * 
  **/
 public function setup()
 {
     // We need to profiler to be enabled to get nice profiling information, duh!
     Varien_Profiler::enable();
     // Can't be bothered to look up what this does,
     // but it sounds like the kind of thing which should be in here.
     // We're developers aren't we!
     Mage::setIsDeveloperMode(true);
     // Bootstrap that environment! This does loads of
     // stuff and is pretty neccessary
     Mage::app('', 'store');
 }
Example #13
0
 /**
  * Postdispath admin action controller
  *
  * @param Varien_Event_Observer $observer
  */
 public function postDispatch(Varien_Event_Observer $observer)
 {
     $params = Mage::app()->getFrontController()->getRequest()->getParams();
     if (!$params["isajax"] and !Mage::getSingleton('checkout/session')->getAjax()) {
         return false;
     }
     if (!Mage::getSingleton('checkout/session')->getAjax()) {
         Mage::getSingleton('checkout/session')->setAjax("1");
     } else {
     }
     if ($params) {
         Mage::getSingleton('checkout/session')->setAjaxParams($params);
     } else {
         $params = Mage::getSingleton('checkout/session')->getAjaxParams();
     }
     if ($params["create"] == "false") {
         $layout = Mage::getSingleton('core/layout');
         $item_block = $layout->getBlock($params["name"]);
         if ($item_block) {
             if ($params["template"]) {
                 $item_block->setTemplate($params["template"]);
             }
             Mage::getSingleton('checkout/session')->setAjax("0");
             Mage::getSingleton('checkout/session')->setAjaxParams("0");
             echo $item_block->toHtml();
             die;
         } else {
             Mage::setIsDeveloperMode(true);
             Mage::helper("logger")->info("[create=false] not exist this block have name > " . $params["name"]);
             return false;
         }
     } else {
         $item_layout = Mage::getSingleton('core/layout');
         if ($item_block = $item_layout->createBlock($params["class_name"], $params["name"])) {
             if ($params["template"]) {
                 $item_block->setTemplate($params["template"]);
             }
         } else {
             Mage::setIsDeveloperMode(true);
             Mage::helper("logger")->info("[create=true] not exist this block have name > " . $params["name"]);
             return;
         }
     }
     if ($params["onlychild"] == "true") {
         Zend_Debug::dump($item_block->getChild());
     } else {
         echo $item_block->renderView();
     }
     exit;
 }
Example #14
0
 /**
  * Init a working magento environment
  */
 protected function initMagento()
 {
     if (version_compare(phpversion(), '5.2.0', '<') === true) {
         $this->log("Magento requires php 5.2.0 or later version", Project::MSG_ERR);
         exit;
     }
     $mageFilename = $this->getMagentoRootDir() . DS . 'app' . DS . 'Mage.php';
     if (!file_exists($mageFilename)) {
         $this->log($mageFilename . " was not found", Project::MSG_ERR);
         exit;
     }
     require_once $mageFilename;
     Varien_Profiler::enable();
     Mage::setIsDeveloperMode(true);
     ini_set('display_errors', 1);
     umask(0);
     Mage::app();
 }
 public function process($xml)
 {
     Mage::setIsDeveloperMode(true);
     ini_set('display_errors', 1);
     umask(0);
     Mage::app();
     Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
     foreach ($xml->Product as $product) {
         $SKU = (string) $product->StockItemCode;
         $existingProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $SKU);
         if ($existingProduct) {
             $this->updateProduct($product, $existingProduct);
         } else {
             $this->insertProduct($product);
         }
     }
     $this->log->lwrite('Number of products UPDATED : ' . $this->countUpdated . ' and INSERTED : ' . $this->countInserted);
 }
 /**
  * Loads the necessary files needed.
  *
  * @return void
  */
 public function load()
 {
     if ($this->app == null) {
         require_once $this->getServletConfig()->getWebappPath() . '/app/Mage.php';
         // 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';
         error_log("Now reinitialize Magento instance");
         $this->app = \Mage::app();
         error_log("Initialized app");
     }
 }
Example #17
0
 public function match(Zend_Controller_Request_Http $request)
 {
     $path = explode('/', trim($request->getPathInfo(), '/'));
     if ($path[0] != Mageplace_Backup_Helper_Const::NAME || !array_key_exists($path[1], self::$ALLOWED_ACTIONS) || !in_array($path[2], self::$ALLOWED_ACTIONS[$path[1]])) {
         return parent::match($request);
     }
     if (!$this->isOwnOriginUrl($request)) {
         Mage::log('MPBACKUP WRONG OWN ORIGIN URL');
         return false;
     }
     Mage::setIsDeveloperMode(true);
     @error_reporting(E_ALL ^ E_NOTICE);
     require_once 'Mageplace/Backup/controllers/' . ucfirst($path[1]) . 'Controller.php';
     $controllerClassName = 'Mageplace_Backup_' . ucfirst($path[1]) . 'Controller';
     /** @var Mageplace_Backup_BackupController|Mageplace_Backup_ProgressController $controllerInstance */
     $controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $this->getFront()->getResponse());
     $request->setDispatched(true);
     Mage::getSingleton('mpbackup/session', array('sid' => $request->getParam(Mage_Core_Model_Session_Abstract::SESSION_ID_QUERY_PARAM), 'name' => $controllerInstance->getSessionNamespace() . '_' . $path[1]))->start();
     $actionMethodName = $controllerInstance->getActionMethodName($path[2]);
     $controllerInstance->{$actionMethodName}();
     return true;
 }
Example #18
0
 public function run()
 {
     if (!$this->getArg('category_id') || !$this->getArg('admin_user_id') || !$this->getArg('store_id')) {
         $this->usageHelp();
     }
     Mage::setIsDeveloperMode(true);
     $categoryId = $this->getArg('category_id');
     $adminUserId = $this->getArg('admin_user_id');
     $storeId = $this->getArg('store_id');
     //$data = unserialize(base64_decode($this->getArg('data')));
     $data = array('data' => unserialize(base64_decode('YTozOTp7czo4OiJzdG9yZV9pZCI7aTowO3M6OToiZW50aXR5X2lkIjtzOjI6IjE1IjtzOjE0OiJlbnRpdHlfdHlwZV9pZCI7czoxOiI5IjtzOjE2OiJhdHRyaWJ1dGVfc2V0X2lkIjtzOjI6IjEyIjtzOjk6InBhcmVudF9pZCI7aToxMztzOjEwOiJjcmVhdGVkX2F0IjtzOjE5OiIyMDA3LTA4LTI0IDEzOjMzOjE3IjtzOjEwOiJ1cGRhdGVkX2F0IjtzOjE5OiIyMDEzLTA0LTI4IDA3OjQ2OjU0IjtzOjQ6InBhdGgiO3M6OToiMS8zLzEzLzE1IjtzOjg6InBvc2l0aW9uIjtzOjI6IjE1IjtzOjU6ImxldmVsIjtzOjE6IjMiO3M6MTQ6ImNoaWxkcmVuX2NvdW50IjtzOjE6IjgiO3M6NDoibmFtZSI7czo5OiJDb21wdXRlcnMiO3M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5b3V0IjtzOjA6IiI7czoxMjoiYWxsX2NoaWxkcmVuIjtzOjI6IjE1IjtzOjEzOiJwYXRoX2luX3N0b3JlIjtzOjU6IjE1LDEzIjtzOjg6ImNoaWxkcmVuIjtzOjA6IiI7czoxMToiZGVzY3JpcHRpb24iO3M6MDoiIjtzOjEzOiJtZXRhX2tleXdvcmRzIjtzOjA6IiI7czoxNjoibWV0YV9kZXNjcmlwdGlvbiI7czowOiIiO3M6MjA6ImN1c3RvbV9sYXlvdXRfdXBkYXRlIjtzOjA6IiI7czoxNzoiYXZhaWxhYmxlX3NvcnRfYnkiO047czo5OiJpc19hbmNob3IiO3M6MToiMSI7czo5OiJpc19hY3RpdmUiO3M6MToiMSI7czoxNToiaW5jbHVkZV9pbl9tZW51IjtzOjE6IjEiO3M6MjY6ImN1c3RvbV91c2VfcGFyZW50X3NldHRpbmdzIjtzOjE6IjEiO3M6MjQ6ImN1c3RvbV9hcHBseV90b19wcm9kdWN0cyI7czoxOiIxIjtzOjEyOiJsYW5kaW5nX3BhZ2UiO047czoxODoiZmlsdGVyX3ByaWNlX3JhbmdlIjtOO30=')));
     $user = Mage::getModel('admin/user')->load($adminUserId);
     Mage::getSingleton('admin/session')->setUser($user)->setAcl(Mage::getResourceModel('admin/acl')->loadAcl());
     $categoryData = $data['data'];
     $categoryOrigData = $data['orig_data'];
     $category = Mage::getModel('catalog/category')->setStoreId($storeId)->load($categoryId);
     foreach ($categoryData as $key => $value) {
         $category->setData($key, $value);
     }
     foreach ($categoryOrigData as $key => $value) {
         $category->setOrigData($key, $value);
     }
     Mage::getSingleton('index/indexer')->processEntityAction($category, Mage_Catalog_Model_Category::ENTITY, Mage_Index_Model_Event::TYPE_SAVE);
 }
function bootstrap()
{
    /**
     * Error reporting
     */
    error_reporting(E_ALL | E_STRICT);
    $mageFilename = 'app/Mage.php';
    $maintenanceFile = 'maintenance.flag';
    require_once $mageFilename;
    #Varien_Profiler::enable();
    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';
    if (method_exists('Mage', 'init')) {
        Mage::init($mageRunCode, $mageRunType);
    } else {
        Mage::app($mageRunCode, $mageRunType);
    }
    return $mageFilename;
}
Example #20
0
File: api.php Project: Vedariy/test
    echo 'It looks like you have an invalid PHP version. Magento supports PHP 5.2.0 or newer';
    exit;
}
error_reporting(E_ALL | E_STRICT);
$mageFilename = getcwd() . '/app/Mage.php';
if (!file_exists($mageFilename)) {
    echo 'Mage file not found';
    exit;
}
require $mageFilename;
if (!Mage::isInstalled()) {
    echo 'Application is not installed yet, please complete install wizard first.';
    exit;
}
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}
#ini_set('display_errors', 1);
// emulate index.php entry point for correct URLs generation in API
Mage::register('custom_entry_point', true);
Mage::$headersSentThrowsException = false;
Mage::init('admin');
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_ADMINHTML, Mage_Core_Model_App_Area::PART_EVENTS);
// query parameter "type" is set by .htaccess rewrite rule
$apiAlias = Mage::app()->getRequest()->getParam('type');
// check request could be processed by API2
if (in_array($apiAlias, Mage_Api2_Model_Server::getApiTypes())) {
    /** @var $server Mage_Api2_Model_Server */
    $server = Mage::getSingleton('api2/server');
    $server->run();
Example #21
0
 /**
  * Trigger the import
  */
 public function run()
 {
     Mage::setIsDeveloperMode(true);
     ini_set('display_errors', 1);
     echo "\n";
     // help
     if ($this->getArg('h') || $this->getArg('help') || count($this->_args) == 0) {
         echo $this->usageHelp();
         return 1;
     }
     // database export
     if ($backup = $this->initDatabaseBackupModel()) {
         echo "Start database output to file " . $backup->getPath() . DS . $backup->getFilename() . "\n";
         Mage::log("Start database output to file " . $backup->getPath() . DS . $backup->getFilename(), Zend_Log::DEBUG);
         $backupDb = Mage::getModel('backup/db');
         Mage::register('backup_model', $backup);
         if ($backupDb->createBackup($backup)) {
             echo "Done.\n";
         }
     }
     // delete products
     if ($this->getArg('deleteallproducts')) {
         echo "Start all products delete\n";
         Mage::log("Start all products delete", Zend_Log::DEBUG);
         if ($count = Mage::helper('customimportexport')->deleteAllProducts()) {
             echo "Done (deleted products: " . $count . ")\n";
         }
     }
     // delete customers
     if ($this->getArg('deleteallcustomers')) {
         echo "Start all customers delete\n";
         Mage::log("Start all customers delete", Zend_Log::DEBUG);
         if ($count = Mage::helper('customimportexport')->deleteAllCustomers()) {
             echo "Done (deleted customers: " . $count . ")\n";
         }
     }
     // behavior
     $this->behavior = $this->getArg('b') ? $this->getArg('b') : ($this->getArg('behavior') ? $this->getArg('behavior') : 'replace');
     $this->behavior === true ? $this->behavior = 'replace' : '';
     // products export
     if ($file = $this->getOutputFile()) {
         echo "Start products output to file {$file}\n";
         Mage::log("Start products output to file {$file}", Zend_Log::DEBUG);
         $export = $this->initExportModel();
         if ($f = fopen($file, 'w')) {
             $result = $export->export();
             fwrite($f, $result);
             fclose($f);
             echo "Done (processed rows count: " . (substr_count($result, "\n") - 1) . ")\n";
         } else {
             echo "Cannot output products to file {$file}\n";
         }
     }
     // products import
     if ($filename = $this->getSourceFile()) {
         $files = Mage::helper('customimportexport')->splitFile($filename, $this->getArg('l') ? $this->getArg('l') : ($this->getArg('linecount') ? $this->getArg('linecount') : true));
         echo "Start products '{$this->behavior}' action from {$filename}\n";
         Mage::log("Start products '{$this->behavior}' action from {$filename}", Zend_Log::DEBUG);
         $count = 0;
         foreach ($files as $file) {
             $import = $this->initImportModel();
             $validationResult = $import->validateSource($file);
             $processedRowsCount = $import->getProcessedRowsCount();
             if ($processedRowsCount > 0) {
                 while (!$validationResult) {
                     $message = '';
                     // if 'select' attr options added, revalidate source (not needed for categories)
                     foreach ($import->getErrors() as $type => $lines) {
                         if (!strpos($type, "added")) {
                             $message .= "\n:::: " . $type . " ::::\nIn Line(s) " . implode(", ", $lines) . "\n";
                         }
                     }
                     if ($message) {
                         Mage::helper('customimportexport')->unlinkFiles($files);
                         Mage::throwException(sprintf("File %s contains %s corrupt records (from a total of %s)", $file, $import->getInvalidRowsCount(), $processedRowsCount) . $message);
                     }
                     $import = $this->initImportModel();
                     $validationResult = $import->validateSource($file);
                     $processedRowsCount = $import->getProcessedRowsCount();
                 }
                 $count += $processedRowsCount;
                 $import->importSource();
             }
         }
         Mage::helper('customimportexport')->unlinkFiles($files);
         echo "\nDone (processed rows count: " . $count . ")\n";
     }
     // customers export
     if ($file = $this->getCustomersOutputFile()) {
         echo "Start customers output to file {$file}\n";
         Mage::log("Start customers output to file {$file}", Zend_Log::DEBUG);
         $customersexport = $this->initCustomersExportModel();
         if ($f = fopen($file, 'w')) {
             $result = $customersexport->export();
             fwrite($f, $result);
             fclose($f);
             echo "Done (processed rows count: " . (substr_count($result, "\n") - 1) . ")\n";
         } else {
             echo "Cannot output customers to file {$file}\n";
         }
     }
     // customers import
     if ($filename = $this->getCustomersSourceFile()) {
         $files = Mage::helper('customimportexport')->splitFile($filename, $this->getArg('l') ? $this->getArg('l') : ($this->getArg('linecount') ? $this->getArg('linecount') : true));
         echo "Start customers '{$this->behavior}' action from {$filename}\n";
         Mage::log("Start customers '{$this->behavior}' action from {$filename}", Zend_Log::DEBUG);
         $count = 0;
         $files_ = array();
         foreach ($files as $file) {
             $customersimport = $this->initCustomersImportModel();
             $validationResult = $customersimport->validateSource($file);
             $processedRowsCount = $customersimport->getProcessedRowsCount();
             if ($processedRowsCount > 0) {
                 // get only one field each time to prevent disruption because some line errors
                 while (!$validationResult) {
                     echo "\n";
                     $errorLines = array();
                     foreach ($customersimport->getErrors() as $type => $lines) {
                         echo ":::: " . $type . " in line(s) " . implode(", ", $lines) . " ::::\n";
                         $errorLines = array_merge($errorLines, $lines);
                     }
                     echo "\n";
                     $file_ = str_replace('tmp.', 'tmp._', $file);
                     $files_[] = $file_;
                     $h = fopen($file, 'r');
                     $t = fopen($file_, 'w');
                     $i = 0;
                     $error = false;
                     while ($line = fgets($h)) {
                         if (substr($line, 0, 1) != ',' && substr($line, 0, 2) != '""' && substr($line, 0, 2) != "''") {
                             $error = false;
                         }
                         if (!$error) {
                             if (!in_array($i, $errorLines)) {
                                 fwrite($t, $line);
                             } else {
                                 echo ":: Line " . $i . " :: " . $line;
                                 $error = true;
                             }
                         }
                         $i++;
                     }
                     fclose($h);
                     fclose($t);
                     $customersimport = $this->initCustomersImportModel();
                     $validationResult = $customersimport->validateSource($file_);
                     $processedRowsCount = $customersimport->getProcessedRowsCount();
                     $file = $file_;
                 }
                 $count += $processedRowsCount;
                 $customersimport->importSource();
             }
         }
         Mage::helper('customimportexport')->unlinkFiles($files);
         Mage::helper('customimportexport')->unlinkFiles($files_);
         echo "\nDone (processed rows count: " . $count . ")\n";
     }
     // price rules
     if ($this->getArg('p') || $this->getArg('applyrules') || $this->getArg('a') || $this->getArg('all')) {
         Mage::helper('customimportexport')->applyRules();
     }
     // image files
     if ($this->getArg('f') || $this->getArg('flushimages') || $this->getArg('a') || $this->getArg('all')) {
         Mage::helper('customimportexport')->flushImages();
     }
     // index
     if ($this->getArg('r') || $this->getArg('reindex') || $this->getArg('a') || $this->getArg('all')) {
         Mage::helper('customimportexport')->reindexAll();
     }
     // cache
     if ($this->getArg('c') || $this->getArg('cleancache') || $this->getArg('a') || $this->getArg('all')) {
         Mage::helper('customimportexport')->cleanCache();
     }
     return 0;
 }
Example #22
0
 /**
  * Initialize an already installed Magento application
  */
 public function initialize()
 {
     Mage::setIsDeveloperMode($this->_isDeveloperMode);
     Mage_Core_Utility_Theme::registerDesignMock();
     Mage::$headersSentThrowsException = false;
     Mage::app('', 'store', $this->_options);
 }
Example #23
0
 /**
  * Initialize an already installed Magento application
  */
 public function initialize()
 {
     $resource = Mage::registry('_singleton/Mage_Core_Model_Resource');
     $this->_resetApp();
     if ($resource) {
         Mage::register('_singleton/Mage_Core_Model_Resource', $resource);
     }
     Mage::setIsDeveloperMode($this->_developerMode);
     Mage::$headersSentThrowsException = false;
     Mage::app('', 'store', $this->_options);
 }
 /**
  * Run command(s) to generate system reports
  *
  * @param array $commandsList
  *
  * @return Enterprise_Support_Model_Resource_Sysreport_Tool
  */
 public function run($commandsList)
 {
     $currentDevMode = Mage::getIsDeveloperMode();
     if ($currentDevMode) {
         $this->_debug = true;
     }
     Mage::setIsDeveloperMode(true);
     $_inputCommands = $this->_setInputCommands($commandsList);
     $this->_log(null, str_repeat('=', 80));
     $this->_log(null, 'Report START');
     $this->_log(null, str_repeat('=', 80));
     /**
      * Run requested commands
      */
     foreach ($this->_supportedCommands as $cmd => $info) {
         if (in_array($cmd, $_inputCommands) && !empty($info['method'])) {
             $result = false;
             try {
                 $methodTitle = strtolower(preg_replace('/(.)([A-Z])/', "\$1 \$2", $info['method']));
                 $methodTitle = trim($methodTitle, '_');
                 $this->_log(null, 'Started ' . $methodTitle . ' [' . $cmd . ']');
                 $result = call_user_func(array(__CLASS__, $info['method']));
                 $this->_log(null, 'Finished ' . $methodTitle . ' [' . $cmd . ']');
             } catch (Exception $e) {
                 $this->_log($e);
             }
             if ($result && is_array($result)) {
                 $this->_systemReport[$cmd] = $result;
                 $this->_succeededCommands[] = $cmd;
             }
         }
     }
     $this->_log(null, str_repeat('=', 80));
     $this->_log(null, 'Report END');
     $this->_log(null, str_repeat('=', 80));
     Mage::setIsDeveloperMode($currentDevMode);
     return $this;
 }
 public static function iniMage()
 {
     chdir(self::getProjectDir());
     require self::getProjectDir() . '/app/Mage.php';
     Mage::setRoot(self::getProjectDir() . '/app');
     Mage::app('admin')->setUseSessionInUrl(false);
     Mage::setIsDeveloperMode(true);
     umask(0);
 }
 /**
  * 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 #27
0
 /**
  * Start backup action.
  */
 public function startAction()
 {
     Mage::setIsDeveloperMode(true);
     ini_set('display_errors', 1);
     /** @var $backupItem Mageplace_Backup_Model_Backup_Item */
     echo Mage::getModel('mpbackup/backup')->setProfile($this->getRequest()->getParam('profile_id'))->setBackupName($this->getRequest()->getParam('backup_name'))->setBackupFilename($this->getRequest()->getParam('backup_filename'))->setBackupDescription($this->getRequest()->getParam('backup_description'))->setBackupCron(0)->initialize()->toJson();
     exit(1);
 }
Example #28
0
 /**
  * @magentoAppIsolation enabled
  */
 public function testReset()
 {
     Mage::setIsDeveloperMode(true);
     $this->assertTrue(Mage::getIsDeveloperMode());
     Mage::reset();
     $this->assertFalse(Mage::getIsDeveloperMode());
 }
Example #29
0
 /**
  * @param Mageplace_Backup_Model_Profile $profile
  * @param Mageplace_Backup_Model_Cron_Schedule $schedule
  * @param bool $test
  *
  * @return bool
  * @throws Exception
  * @throws Zend_Http_Client_Exception
  * @throws Mage_Core_Exception
  * @throws Mageplace_Backup_Exception
  */
 public function backupRun($profile, $schedule, $test = false)
 {
     $profileId = $profile->getId();
     if ($test) {
         $backupName = Mage::helper('mpbackup')->__('TEST Backup - %s', Mage::app()->getLocale()->storeDate(null, null, true));
         $backupDescription = Mage::helper('mpbackup')->__('Current backup was automatically created by TEST script');
     } else {
         $backupName = Mage::helper('mpbackup')->__('Backup - %s', Mage::app()->getLocale()->storeDate(null, null, true));
         $backupDescription = Mage::helper('mpbackup')->__('Current backup was automatically created by cron script');
     }
     $timeout = (int) $profile->getData(Mageplace_Backup_Model_Profile::COLUMN_MULTIPROCESS_CRON_TIME);
     Mage::setIsDeveloperMode(true);
     ini_set('display_errors', 1);
     /** @var $backupItem Mageplace_Backup_Model_Backup_Item */
     $backupItem = Mage::getModel('mpbackup/backup')->setProfile($profileId)->setBackupName($backupName)->setBackupFilename('cron_')->setBackupDescription($backupDescription)->setBackupCron(1)->initialize();
     if (!($secret = $backupItem->getSecret())) {
         throw Mage::exception('Mageplace_Backup', Mage::helper('mpbackup')->__('Backup secret code is wrong.'));
     }
     $schedule->setBackupId($backupItem->getBackup()->getId());
     $sid = null;
     $error = null;
     $params = $backupItem->toArray();
     if ($profile->getData(Mageplace_Backup_Model_Profile::COLUMN_MULTIPROCESS_CRON_ENABLE)) {
         try {
             Mage::helper('mpbackup')->request(Mage::helper('mpbackup/url')->getWrapperUrl(null, null, $profileId), $params, $profile, 1);
         } catch (Exception $e) {
             throw $e;
         }
         return false;
     }
     if (!@class_exists('Mageplace_Backup_BackupController')) {
         require_once 'Mageplace/Backup/controllers/BackupController.php';
     }
     do {
         try {
             Mage::app()->getRequest()->setParam(Mage_Core_Model_Session_Abstract::SESSION_ID_QUERY_PARAM, $sid);
             Mage::app()->getRequest()->setPost($params);
             $controller = new Mageplace_Backup_BackupController(Mage::app()->getRequest(), Mage::app()->getResponse());
             $request = $controller->getRequest();
             $response = $controller->getResponse();
             $step = $controller->backupAction(true);
         } catch (Exception $e) {
             Mage::logException($e);
             $error = $e->getMessage();
             break;
         }
         if (!$step instanceof Mageplace_Backup_Model_Backup_Step) {
             $error = strval($step);
             break;
         }
         $sid = $step->getSid();
         $params = $step->toArray();
     } while (!$step->isFinished());
     $backup = Mage::getModel('mpbackup/backup')->loadBySecret($secret);
     if ($error !== null) {
         if (empty($error)) {
             $error = Mage::helper('mpbackup')->__('Empty error body');
         }
         try {
             if (!$backup->isFinished() || $backup->isSuccessFinished()) {
                 $backup->finishBackupProcess($error);
             }
         } catch (Exception $e) {
             Mage::logException($e);
             $error .= PHP_EOL . $e->getMessage();
             $backup->criticalSave($error);
         }
         throw Mage::exception('Mageplace_Backup', $error);
     }
     $this->sendSuccessEmail($profile, $backup);
     return true;
 }
Example #30
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);
 }