Ejemplo n.º 1
0
 /**
  * Create .htaccess file and deny backups directory access from web
  */
 protected function _hideBackupsForApache()
 {
     $htaccessPath = $this->_baseDir . DS . '.htaccess';
     if (!$this->_filesystem->isFile($htaccessPath)) {
         $this->_filesystem->write($htaccessPath, 'deny from all');
         $this->_filesystem->changePermissions($htaccessPath, 0644);
     }
 }
Ejemplo n.º 2
0
 /**
  * Add image to media gallery and return new filename
  *
  * @param Mage_Catalog_Model_Product $product
  * @param string                     $file              file path of image in file system
  * @param string|array               $mediaAttribute    code of attribute with type 'media_image',
  *                                                      leave blank if image should be only in gallery
  * @param boolean                    $move              if true, it will move source file
  * @param boolean                    $exclude           mark image as disabled in product page view
  * @return string
  */
 public function addImage(Mage_Catalog_Model_Product $product, $file, $mediaAttribute = null, $move = false, $exclude = true)
 {
     if (!$this->_filesystem->isFile($file, $this->_baseTmpMediaPath)) {
         Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Image does not exist.'));
     }
     Mage::dispatchEvent('catalog_product_media_add_image', array('product' => $product, 'image' => $file));
     $pathinfo = pathinfo($file);
     $imgExtensions = array('jpg', 'jpeg', 'gif', 'png');
     if (!isset($pathinfo['extension']) || !in_array(strtolower($pathinfo['extension']), $imgExtensions)) {
         Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Invalid image file type.'));
     }
     $fileName = Mage_Core_Model_File_Uploader::getCorrectFileName($pathinfo['basename']);
     $dispretionPath = Mage_Core_Model_File_Uploader::getDispretionPath($fileName);
     $fileName = $dispretionPath . DS . $fileName;
     $fileName = $this->_getNotDuplicatedFilename($fileName, $dispretionPath);
     $destinationFile = $this->_getConfig()->getTmpMediaPath($fileName);
     try {
         /** @var $storageHelper Mage_Core_Helper_File_Storage_Database */
         $storageHelper = Mage::helper('Mage_Core_Helper_File_Storage_Database');
         if ($move) {
             $this->_filesystem->rename($file, $destinationFile, $this->_baseTmpMediaPath);
             //If this is used, filesystem should be configured properly
             $storageHelper->saveFile($this->_getConfig()->getTmpMediaShortUrl($fileName));
         } else {
             $this->_filesystem->copy($file, $destinationFile, $this->_baseTmpMediaPath);
             $storageHelper->saveFile($this->_getConfig()->getTmpMediaShortUrl($fileName));
             $this->_filesystem->changePermissions($destinationFile, 0777, false, $this->_baseTmpMediaPath);
         }
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('Mage_Catalog_Helper_Data')->__('Failed to move file: %s', $e->getMessage()));
     }
     $fileName = str_replace(DS, '/', $fileName);
     $attrCode = $this->getAttribute()->getAttributeCode();
     $mediaGalleryData = $product->getData($attrCode);
     $position = 0;
     if (!is_array($mediaGalleryData)) {
         $mediaGalleryData = array('images' => array());
     }
     foreach ($mediaGalleryData['images'] as &$image) {
         if (isset($image['position']) && $image['position'] > $position) {
             $position = $image['position'];
         }
     }
     $position++;
     $mediaGalleryData['images'][] = array('file' => $fileName, 'position' => $position, 'label' => '', 'disabled' => (int) $exclude);
     $product->setData($attrCode, $mediaGalleryData);
     if (!is_null($mediaAttribute)) {
         $this->setMediaAttribute($product, $mediaAttribute, $fileName);
     }
     return $fileName;
 }
Ejemplo n.º 3
0
 public function install()
 {
     $data = $this->getConfigData();
     foreach (Mage::getModel('Mage_Core_Model_Config')->getDistroServerVars() as $index => $value) {
         if (!isset($data[$index])) {
             $data[$index] = $value;
         }
     }
     if (isset($data['unsecure_base_url'])) {
         $data['unsecure_base_url'] .= substr($data['unsecure_base_url'], -1) != '/' ? '/' : '';
         if (strpos($data['unsecure_base_url'], 'http') !== 0) {
             $data['unsecure_base_url'] = 'http://' . $data['unsecure_base_url'];
         }
         if (!$this->_getInstaller()->getDataModel()->getSkipBaseUrlValidation()) {
             $this->_checkUrl($data['unsecure_base_url']);
         }
     }
     if (isset($data['secure_base_url'])) {
         $data['secure_base_url'] .= substr($data['secure_base_url'], -1) != '/' ? '/' : '';
         if (strpos($data['secure_base_url'], 'http') !== 0) {
             $data['secure_base_url'] = 'https://' . $data['secure_base_url'];
         }
         if (!empty($data['use_secure']) && !$this->_getInstaller()->getDataModel()->getSkipUrlValidation()) {
             $this->_checkUrl($data['secure_base_url']);
         }
     }
     $data['date'] = self::TMP_INSTALL_DATE_VALUE;
     $data['key'] = self::TMP_ENCRYPT_KEY_VALUE;
     $data['var_dir'] = $data['root_dir'] . '/var';
     $data['use_script_name'] = isset($data['use_script_name']) ? 'true' : 'false';
     $this->_getInstaller()->getDataModel()->setConfigData($data);
     $template = $this->_filesystem->read(Mage::getBaseDir('etc') . DS . 'local.xml.template');
     foreach ($data as $index => $value) {
         $template = str_replace('{{' . $index . '}}', '<![CDATA[' . $value . ']]>', $template);
     }
     $this->_filesystem->write($this->_localConfigFile, $template);
     $this->_filesystem->changePermissions($this->_localConfigFile, 0777);
 }
Ejemplo n.º 4
0
 /**
  * Install Magento
  *
  * @param array $options
  * @return string|boolean
  */
 public function install(array $options)
 {
     try {
         $options = $this->_getInstallOptions($options);
         if (!$options) {
             return false;
         }
         /**
          * Check if already installed
          */
         if (Mage::isInstalled()) {
             $this->addError('ERROR: Magento is already installed.');
             return false;
         }
         /**
          * Skip URL validation, if set
          */
         $this->_getDataModel()->setSkipUrlValidation($options['skip_url_validation']);
         $this->_getDataModel()->setSkipBaseUrlValidation($options['skip_url_validation']);
         /**
          * Locale settings
          */
         $this->_getDataModel()->setLocaleData(array('locale' => $options['locale'], 'timezone' => $options['timezone'], 'currency' => $options['default_currency']));
         /**
          * Database and web config
          */
         $this->_getDataModel()->setConfigData(array('db_model' => $options['db_model'], 'db_host' => $options['db_host'], 'db_name' => $options['db_name'], 'db_user' => $options['db_user'], 'db_pass' => $options['db_pass'], 'db_prefix' => $options['db_prefix'], 'use_rewrites' => $this->_getFlagValue($options['use_rewrites']), 'use_secure' => $this->_getFlagValue($options['use_secure']), 'unsecure_base_url' => $options['url'], 'secure_base_url' => $options['secure_base_url'], 'use_secure_admin' => $this->_getFlagValue($options['use_secure_admin']), 'session_save' => $this->_checkSessionSave($options['session_save']), 'backend_frontname' => $this->_checkBackendFrontname($options['backend_frontname']), 'admin_no_form_key' => $this->_getFlagValue($options['admin_no_form_key']), 'skip_url_validation' => $this->_getFlagValue($options['skip_url_validation']), 'enable_charts' => $this->_getFlagValue($options['enable_charts']), 'order_increment_prefix' => $options['order_increment_prefix']));
         /**
          * Primary admin user
          */
         $this->_getDataModel()->setAdminData(array('firstname' => $options['admin_firstname'], 'lastname' => $options['admin_lastname'], 'email' => $options['admin_email'], 'username' => $options['admin_username'], 'new_password' => $options['admin_password']));
         $installer = $this->_getInstaller();
         /**
          * Install configuration
          */
         $installer->installConfig($this->_getDataModel()->getConfigData());
         if (!empty($options['cleanup_database'])) {
             $this->_cleanUpDatabase();
         }
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Install database
          */
         $installer->installDb();
         if ($this->hasErrors()) {
             return false;
         }
         // apply data updates
         Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
         /**
          * Validate entered data for administrator user
          */
         $user = $installer->validateAndPrepareAdministrator($this->_getDataModel()->getAdminData());
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Prepare encryption key and validate it
          */
         $encryptionKey = empty($options['encryption_key']) ? $this->generateEncryptionKey() : $options['encryption_key'];
         $this->_getDataModel()->setEncryptionKey($encryptionKey);
         $installer->validateEncryptionKey($encryptionKey);
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Create primary administrator user
          */
         $installer->createAdministrator($user);
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Save encryption key or create if empty
          */
         $installer->installEnryptionKey($encryptionKey);
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Installation finish
          */
         $installer->finish();
         if ($this->hasErrors()) {
             return false;
         }
         /**
          * Change directories mode to be writable by apache user
          */
         $this->_filesystem->changePermissions(Mage::getBaseDir('var'), 0777, true);
         return $encryptionKey;
     } catch (Exception $e) {
         $this->addError('ERROR: ' . $e->getMessage());
         return false;
     }
 }