/**
  * Load unique entities records into items
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @throws Exception
  * @return Mage_ConfigurableSwatches_Model_Resource_Catalog_Product_Type_Configurable_Product_Collection
  */
 public function _loadEntities($printQuery = false, $logQuery = false)
 {
     if ($this->_pageSize) {
         $this->getSelect()->limitPage($this->getCurPage(), $this->_pageSize);
     }
     $this->printLogQuery($printQuery, $logQuery);
     try {
         /**
          * Prepare select query
          * @var string $query
          */
         $query = $this->_prepareSelect($this->getSelect());
         $rows = $this->_fetchAll($query);
     } catch (Exception $e) {
         Mage::printException($e, $query);
         $this->printLogQuery(true, true, $query);
         throw $e;
     }
     foreach ($rows as $v) {
         if (!isset($this->_items[$v['entity_id']])) {
             $object = $this->getNewEmptyItem()->setData($v)->setParentIds(array($v['parent_id']));
             $this->addItem($object);
             if (isset($this->_itemsById[$object->getId()])) {
                 $this->_itemsById[$object->getId()][] = $object;
             } else {
                 $this->_itemsById[$object->getId()] = array($object);
             }
         } else {
             $parents = $this->_items[$v['entity_id']]->getParentIds();
             $parents[] = $v['parent_id'];
             $this->_items[$v['entity_id']]->setParentIds($parents);
         }
     }
     return $this;
 }
        $options = getopt('m::');
        if (isset($options['m'])) {
            if ($options['m'] == 'always') {
                $cronMode = 'always';
            } elseif ($options['m'] == 'default') {
                $cronMode = 'default';
            } else {
                Mage::throwException('Unrecognized cron mode was defined');
            }
        } else {
            if (!$isShellDisabled) {
                $fileName = basename(__FILE__);
                $baseDir = dirname(__FILE__);
                shell_exec("/bin/sh {$baseDir}/cron.sh {$fileName} -mdefault 1 > /dev/null 2>&1 &");
                shell_exec("/bin/sh {$baseDir}/cron.sh {$fileName} -malways 1 > /dev/null 2>&1 &");
                exit;
            }
        }
    }
    Mage::getConfig()->init()->loadEventObservers('crontab');
    Mage::app()->addEventArea('crontab');
    if ($isShellDisabled) {
        Mage::dispatchEvent('always');
        Mage::dispatchEvent('default');
    } else {
        Mage::dispatchEvent($cronMode);
    }
} catch (Exception $e) {
    Mage::printException($e);
    exit(1);
}
Example #3
0
 public function installFailure($observer)
 {
     echo "<h2>There was a problem proceeding with Magento installation.</h2>";
     echo "<p>Please contact developers with error messages on this page.</p>";
     echo Mage::printException($observer->getEvent()->getException());
 }
Example #4
0
 /**
  * Load attributes into loaded entities
  *
  * @throws Exception
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function _loadAttributes($printQuery = false, $logQuery = false)
 {
     if (empty($this->_items) || empty($this->_itemsById) || empty($this->_selectAttributes)) {
         return $this;
     }
     $entity = $this->getEntity();
     $tableAttributes = array();
     $attributeTypes = array();
     foreach ($this->_selectAttributes as $attributeCode => $attributeId) {
         if (!$attributeId) {
             continue;
         }
         $attribute = Mage::getSingleton('eav/config')->getCollectionAttribute($entity->getType(), $attributeCode);
         if ($attribute && !$attribute->isStatic()) {
             $tableAttributes[$attribute->getBackendTable()][] = $attributeId;
             if (!isset($attributeTypes[$attribute->getBackendTable()])) {
                 $attributeTypes[$attribute->getBackendTable()] = $attribute->getBackendType();
             }
         }
     }
     $selects = array();
     foreach ($tableAttributes as $table => $attributes) {
         $select = $this->_getLoadAttributesSelect($table, $attributes);
         $selects[$attributeTypes[$table]][] = $this->_addLoadAttributesSelectValues($select, $table, $attributeTypes[$table]);
     }
     $selectGroups = Mage::getResourceHelper('eav')->getLoadAttributesSelectGroups($selects);
     foreach ($selectGroups as $selects) {
         if (!empty($selects)) {
             try {
                 $select = implode(' UNION ALL ', $selects);
                 $values = $this->getConnection()->fetchAll($select);
             } catch (Exception $e) {
                 Mage::printException($e, $select);
                 $this->printLogQuery(true, true, $select);
                 throw $e;
             }
             foreach ($values as $value) {
                 $this->_setItemAttributeValue($value);
             }
         }
     }
     return $this;
 }
Example #5
0
 /**
  * Load attributes into loaded entities
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function _loadAttributes($printQuery = false, $logQuery = false)
 {
     if (empty($this->_items) || empty($this->_itemsById) || empty($this->_selectAttributes)) {
         return $this;
     }
     $entity = $this->getEntity();
     $entityIdField = $entity->getEntityIdField();
     $tableAttributes = array();
     foreach ($this->_selectAttributes as $attributeCode => $attributeId) {
         $attribute = Mage::getSingleton('eav/config')->getCollectionAttribute($entity->getType(), $attributeCode);
         if ($attribute && !$attribute->isStatic()) {
             $tableAttributes[$attribute->getBackendTable()][] = $attributeId;
         }
     }
     foreach ($tableAttributes as $table => $attributes) {
         $select = $this->_getLoadAttributesSelect($table);
         try {
             $values = $this->_fetchAll($select, $attributes);
         } catch (Exception $e) {
             Mage::printException($e, $select);
             $this->printLogQuery(true, true, $select);
             throw $e;
         }
         foreach ($values as $value) {
             $this->_setItemAttributeValue($value);
         }
     }
     return $this;
 }
 /**
  * Load entities records into items
  *
  * Removed page limiting SQL from this method to prevent issues with paging and Klevu.
  *
  * @throws Exception
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function _loadEntities($printQuery = false, $logQuery = false)
 {
     if (!$this->isExtensionConfigured()) {
         return parent::_loadEntities($printQuery, $logQuery);
     }
     // API results are already filtered, so include only the products
     // returned by the API in the collection
     $this->getSelect()->reset(Zend_Db_Select::WHERE);
     $this->addFieldToFilter('entity_id', array('in' => $this->_getProductIds()));
     // API results are ordered using the selected sort order, so enforce
     // the collection order to match the API results
     $this->getSelect()->reset(Zend_Db_Select::ORDER);
     $this->getSelect()->reset(Zend_Db_Select::LIMIT_OFFSET);
     if (count($this->_getProductIds())) {
         // Use "FIELD (column, 1[,2,3,4]) ASC" for ordering, where "1[,2,3,4]" is the list of IDs in the order required
         $this->getSelect()->order(sprintf('FIELD(`e`.`entity_id`, %s) ASC', implode(',', $this->_getProductIds())));
     }
     $this->printLogQuery($printQuery, $logQuery);
     try {
         /**
          * Prepare select query
          * @var string $query
          */
         if (is_callable(array($this, "_prepareSelect"))) {
             $query = $this->_prepareSelect($this->getSelect());
         } else {
             $query = $this->getSelect();
         }
         $rows = $this->_fetchAll($query);
     } catch (Exception $e) {
         Mage::printException($e, $query);
         $this->printLogQuery(true, true, $query);
         throw $e;
     }
     foreach ($rows as $v) {
         $object = $this->getNewEmptyItem()->setData($v);
         $this->addItem($object);
         if (isset($this->_itemsById[$object->getId()])) {
             $this->_itemsById[$object->getId()][] = $object;
         } else {
             $this->_itemsById[$object->getId()] = array($object);
         }
     }
     return $this;
 }
Example #7
0
 /**
  * Load attributes into loaded entities
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function _loadAttributes($printQuery = false, $logQuery = false)
 {
     if (empty($this->_items) || empty($this->_itemsById) || empty($this->_selectAttributes)) {
         return $this;
     }
     $entity = $this->getEntity();
     $entityIdField = $entity->getEntityIdField();
     foreach ($entity->getAttributesByTable() as $table => $attributes) {
         $select = $this->_getLoadAttributesSelect($table);
         try {
             $values = $this->_fetchAll($select);
         } catch (Exception $e) {
             Mage::printException($e, $select);
             $this->printLogQuery(true, true, $select);
             throw $e;
         }
         foreach ($values as $value) {
             $this->_setItemAttributeValue($value);
         }
     }
     return $this;
 }
 /**
  * Load entities records into items
  *
  * @param bool $printQuery
  * @param bool $logQuery
  *
  * @throws Exception
  * @throws Mage_Core_Exception
  *
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function _loadEntities($printQuery = false, $logQuery = false)
 {
     // get product IDs from Fact-Finder
     $productIds = $this->_getSearchHandler()->getSearchResult();
     if (!empty($productIds)) {
         $idFieldName = Mage::helper('factfinder/search')->getIdFieldName();
         // add Filter to Query
         $this->addFieldToFilter($idFieldName, array('in' => array_keys($productIds)));
         $this->_pageSize = null;
         $this->getSelect()->reset(Zend_Db_Select::LIMIT_COUNT);
         $this->getSelect()->reset(Zend_Db_Select::LIMIT_OFFSET);
         $this->printLogQuery($printQuery, $logQuery);
         Mage::helper('factfinder/debug')->log('Search SQL Query: ' . $this->getSelect()->__toString());
         try {
             $rows = $this->_fetchAll($this->getSelect());
         } catch (Exception $e) {
             Mage::printException($e, $this->getSelect());
             $this->printLogQuery(true, true, $this->getSelect());
             throw $e;
         }
         $items = array();
         foreach ($rows as $v) {
             $items[trim($v[$idFieldName])] = $v;
         }
         foreach ($productIds as $productId => $additionalData) {
             if (empty($items[$productId])) {
                 continue;
             }
             $v = array_merge($items[$productId], $additionalData->toArray());
             $object = $this->getNewEmptyItem()->setData($v);
             $this->addItem($object);
             if (isset($this->_itemsById[$object->getId()])) {
                 $this->_itemsById[$object->getId()][] = $object;
             } else {
                 $this->_itemsById[$object->getId()] = array($object);
             }
         }
     }
     return $this;
 }
 /**
  * Load entities records into items
  *
  * @param bool $printQuery
  * @param bool $logQuery
  *
  * @throws Exception
  *
  * @return FACTFinder_Campaigns_Model_Resource_Pushedproducts_Collection
  */
 public function _loadEntities($printQuery = false, $logQuery = false)
 {
     $productIds = array();
     $campaigns = $this->_getCampaigns();
     if (!$campaigns) {
         return $this;
     }
     foreach ($campaigns->getPushedProducts() as $record) {
         $productIds[$record->getId()] = new Varien_Object(array('similarity' => $record->getSimilarity(), 'position' => $record->getPosition()));
     }
     $idFieldName = Mage::helper('factfinder_campaigns')->getIdFieldName();
     if (!empty($productIds)) {
         // add Filter to Query
         $this->addFieldToFilter($idFieldName, array('in' => array_keys($productIds)));
         $this->_pageSize = null;
         $this->getSelect()->reset(Zend_Db_Select::LIMIT_COUNT);
         $this->getSelect()->reset(Zend_Db_Select::LIMIT_OFFSET);
         $this->printLogQuery($printQuery, $logQuery);
         Mage::helper('factfinder/debug')->log('Search SQL Query: ' . $this->getSelect()->__toString());
         try {
             $rows = $this->_fetchAll($this->getSelect());
         } catch (Exception $e) {
             Mage::printException($e, $this->getSelect());
             $this->printLogQuery(true, true, $this->getSelect());
             throw $e;
         }
         $items = array();
         foreach ($rows as $v) {
             $items[$v[$idFieldName]] = $v;
         }
         foreach ($productIds as $productId => $additionalData) {
             if (empty($items[$productId])) {
                 continue;
             }
             $v = array_merge($items[$productId], $additionalData->toArray());
             $object = $this->getNewEmptyItem()->setData($v);
             $this->addItem($object);
             if (isset($this->_itemsById[$object->getId()])) {
                 $this->_itemsById[$object->getId()][] = $object;
             } else {
                 $this->_itemsById[$object->getId()] = array($object);
             }
         }
     }
     return $this;
 }