예제 #1
0
 /**
  *  Handles LiveCart update process
  */
 public function update()
 {
     $dir = ClassLoader::getRealPath('update') . '/' . $this->getCurrentVersion();
     if (!is_dir($dir)) {
         return new RawResponse('Update directory not found');
     }
     $progress = array();
     $errors = array();
     // load SQL dump file
     $sql = $dir . '/update.sql';
     if (file_exists($sql)) {
         try {
             Installer::loadDatabaseDump(file_get_contents($sql), true, $this->request->get('force'));
             $progress['sql'] = true;
         } catch (Exception $e) {
             $errors['sql'] = $e->getMessage();
         }
     }
     $this->application->getConfigContainer()->clearCache();
     // execute custom update code
     $code = $dir . '/custom.php';
     if (file_exists($code)) {
         ob_start();
         if (!(include $code)) {
             $errors['code'] = ob_get_contents();
         } else {
             $progress['code'] = true;
         }
         ob_end_clean();
     }
     $response = new ActionResponse();
     $response->set('progress', $progress);
     $response->set('errors', $errors);
     return $response;
 }
예제 #2
0
 public function import()
 {
     $this->application->setDevMode(true);
     ignore_user_abort(true);
     ini_set('memory_limit', '512M');
     set_time_limit(0);
     if ($this->request->get('password') != $this->config->get('CLONE_STORE_API_KEY')) {
         return new RawResponse('Wrong password');
     }
     ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0;');
     ActiveRecord::getLogger()->setLogFileName(null);
     $dir = $this->getFileDir();
     //if (ob_get_length())
     //{
     ob_flush();
     ob_end_clean();
     //}
     //echo str_repeat('FLUSH ', 10000);
     foreach (scandir($dir) as $file) {
         if (strlen($file) < 3) {
             continue;
         }
         $path = $dir . $file;
         if (substr($file, -4) == '.sql') {
             $f = fopen($path, 'r');
             $prev = '';
             while (!feof($f)) {
                 $s = $prev . fread($f, 1024 * 1024);
                 if (!feof($f)) {
                     $pos = strrpos($s, ";\n");
                     $prev = substr($s, $pos + 1);
                     $s = substr($s, 0, $pos);
                 }
                 Installer::loadDatabaseDump($s, true);
             }
         } else {
             $this->untar($path, ClassLoader::getRealPath('public.upload.'));
         }
         unlink($path);
     }
     $this->user->allowBackendAccess();
     $c = new ProductImageController($this->application);
     $c->resizeImages();
     Category::reindex();
     Category::recalculateProductsCount();
 }
예제 #3
0
 public function setDatabase()
 {
     set_time_limit(0);
     if (!$this->buildDatabaseValidator()->isValid()) {
         return new ActionRedirectResponse('install', 'database');
     }
     $type = function_exists('mysql_connect') ? 'mysql' : 'mysqli';
     $dsn = $type . '://' . $this->request->get('username') . ($this->request->get('password') ? ':' . $this->request->get('password') : '') . '@' . $this->request->get('server') . '/' . $this->request->get('name');
     ClassLoader::import('library.activerecord.ActiveRecord');
     ActiveRecord::resetDBConnection();
     ActiveRecord::setDSN($dsn);
     try {
         $conn = ActiveRecord::getDBConnection();
         // test if InnoDB tables can be created
         $table = 'TestInnoDB';
         $create = 'CREATE TABLE ' . $table . ' (ID INTEGER) ENGINE = INNODB';
         $drop = 'DROP TABLE ' . $table;
         ActiveRecord::executeUpdate($create);
         $data = ActiveRecord::getDataBySQL('SHOW TABLE STATUS');
         ActiveRecord::executeUpdate($drop);
         foreach ($data as $row) {
             if (strtolower($row['Name']) == strtolower($table)) {
                 if (strtolower($row['Engine']) != 'innodb') {
                     throw new SQLException('', $this->translate('_err_innodb_not_available'));
                 }
             }
         }
         $dsnFile = $this->getDsnFile();
         if (!file_exists(dirname($dsnFile))) {
             mkdir(dirname($dsnFile), 0777, true);
         }
         ActiveRecord::beginTransaction();
         //ActiveRecord::executeUpdate('SET FOREIGN_KEY_CHECKS = 0');
         //ActiveRecord::executeUpdate('DROP TABLE `AccessControlAssociation`, `AdAdvertiser`, `AdAdvertiserUser`, `AdBanner`, `AdBannerStats`, `AdCampaign`, `AdCampaignCondition`, `AdZone`, `Author`, `AuthorImage`, `BillingAddress`, `Category`, `CategoryImage`, `CategoryPresentation`, `CategorySubscribeCategory`, `CategorySubscribeQueue`, `CategorySubscribeUser`, `Currency`, `CustomerOrder`, `DeliveryZone`, `DeliveryZoneAddressMask`, `DeliveryZoneCityMask`, `DeliveryZoneCountry`, `DeliveryZoneRealTimeService`, `DeliveryZoneState`, `DeliveryZoneWarehouse`, `DeliveryZoneZipMask`, `Discount`, `DiscountAction`, `DiscountCondition`, `DiscountConditionRecord`, `EavDateValue`, `EavField`, `EavFieldGroup`, `EavItem`, `EavNumericValue`, `EavObject`, `EavStringValue`, `EavValue`, `ExpressCheckout`, `Filter`, `FilterGroup`, `HelpComment`, `Language`, `Manufacturer`, `ManufacturerImage`, `NewsletterMessage`, `NewsletterSentMessage`, `NewsletterSubscriber`, `NewsPost`, `OrderCoupon`, `OrderDiscount`, `OrderedItem`, `OrderedItemOption`, `OrderLog`, `OrderNote`, `PostalCode`, `Product`, `ProductBundle`, `ProductCategory`, `ProductFile`, `ProductFileGroup`, `ProductImage`, `ProductList`, `ProductListItem`, `ProductOption`, `ProductOptionChoice`, `ProductPrice`, `ProductRating`, `ProductRatingSummary`, `ProductRatingType`, `ProductRelationship`, `ProductRelationshipGroup`, `ProductReview`, `ProductVariation`, `ProductVariationTemplate`, `ProductVariationType`, `ProductVariationValue`, `ProductWarehouse`, `PurchasePointsItemOrder`, `PurchasePointsOrder`, `PurchasePointsUser`, `RecurringProductPeriod`, `RewardPointsOrder`, `RewardPointsUser`, `Role`, `SearchLog`, `SessionData`, `Shipment`, `ShipmentTax`, `ShipmentWarehouse`, `ShippingAddress`, `ShippingRate`, `ShippingService`, `SpecField`, `SpecFieldGroup`, `SpecFieldValue`, `SpecificationDateValue`, `SpecificationItem`, `SpecificationNumericValue`, `SpecificationStringValue`, `State`, `StaticPage`, `Tax`, `TaxRate`, `Transaction`, `User`, `UserAddress`, `UserGroup`, `Warehouse`');
         // import schema
         Installer::loadDatabaseDump(file_get_contents(ClassLoader::getRealPath('installdata.sql') . '/create.sql'), true);
         // create root category
         Installer::loadDatabaseDump(file_get_contents(ClassLoader::getRealPath('installdata.sql') . '/initialData.sql'), true);
         // states
         Installer::loadDatabaseDump(file_get_contents(ClassLoader::getRealPath('installdata.sql.state') . '/all.sql'), true);
         file_put_contents($dsnFile, '<?php return ' . var_export($dsn, true) . '; ?>');
         ActiveRecord::commit();
         return new ActionResponse();
         //return new ActionRedirectResponse('install', 'admin');
     } catch (SQLException $e) {
         $validator = $this->buildDatabaseValidator();
         $validator->triggerError('connect', $e->getNativeError());
         $validator->saveState();
         return new ActionResponse('step', 'database');
         //return new ActionRedirectResponse('install', 'database');
     }
 }
예제 #4
0
 protected function loadSQL($file)
 {
     ClassLoader::import('application.model.system.Installer');
     if (file_exists($file)) {
         return Installer::loadDatabaseDump(file_get_contents($file));
     } else {
         return true;
     }
 }