예제 #1
0
	protected function stageConvertTree()
	{
		if($this->getStep() == 0)
		{
			$this->migrator->convertTree();
			$this->nextStep();
		}
		else
		{
			Location\LocationTable::resetLegacyPath();
			$this->nextStage();
		}
	}
예제 #2
0
 public static function importFile(&$descriptior)
 {
     $timeLimit = ini_get('max_execution_time');
     if ($timeLimit < $descriptior['TIME_LIMIT']) {
         set_time_limit($descriptior['TIME_LIMIT'] + 5);
     }
     $endTime = time() + $descriptior['TIME_LIMIT'];
     if ($descriptior['STEP'] == 'rebalance') {
         Location\LocationTable::resort();
         Location\LocationTable::resetLegacyPath();
         $descriptior['STEP'] = 'done';
     }
     if ($descriptior['STEP'] == 'import') {
         if (!isset($descriptior['DO_SYNC'])) {
             $res = \Bitrix\Sale\Location\LocationTable::getList(array('select' => array('CNT')))->fetch();
             $descriptior['DO_SYNC'] = intval($res['CNT'] > 0);
         }
         if (!isset($descriptior['TYPES'])) {
             $descriptior['TYPE_MAP'] = static::getTypeMap($descriptior['TYPE_FILE']);
             $descriptior['TYPES'] = static::createTypes($descriptior['TYPE_MAP']);
             $descriptior['SERVICE_MAP'] = static::getServiceMap($descriptior['SERVICE_FILE']);
             $descriptior['SERVICES'] = static::getExistedServices();
         }
         $csvReader = new CSVReader();
         $csvReader->LoadFile($descriptior['FILE']);
         while (time() < $endTime) {
             $block = $csvReader->ReadBlockLowLevel($descriptior['POS'], 100);
             if (!count($block)) {
                 break;
             }
             foreach ($block as $item) {
                 if ($descriptior['DO_SYNC']) {
                     $id = static::checkLocationCodeExists($item['CODE']);
                     if ($id) {
                         $descriptior['CODES'][$item['CODE']] = $id;
                         continue;
                     }
                 }
                 // type
                 $item['TYPE_ID'] = $descriptior['TYPES'][$item['TYPE_CODE']];
                 unset($item['TYPE_CODE']);
                 // parent id
                 if (strlen($item['PARENT_CODE'])) {
                     if (!isset($descriptior['CODES'][$item['PARENT_CODE']])) {
                         $descriptior['CODES'][$item['PARENT_CODE']] = static::checkLocationCodeExists($item['PARENT_CODE']);
                     }
                     $item['PARENT_ID'] = $descriptior['CODES'][$item['PARENT_CODE']];
                 }
                 unset($item['PARENT_CODE']);
                 // ext
                 if (is_array($item['EXT'])) {
                     foreach ($item['EXT'] as $code => $values) {
                         if (is_array($values) && !empty($values)) {
                             if (!isset($descriptior['SERVICES'][$code])) {
                                 $descriptior['SERVICES'][$code] = static::createService(array('CODE' => $code));
                             }
                             foreach ($values as $value) {
                                 if (!strlen($value)) {
                                     continue;
                                 }
                                 $item['EXTERNAL'][] = array('SERVICE_ID' => $descriptior['SERVICES'][$code], 'XML_ID' => $value);
                             }
                         }
                     }
                 }
                 unset($item['EXT']);
                 $res = Location\LocationTable::add($item, array('REBALANCE' => false, 'RESET_LEGACY' => false));
                 if (!$res->isSuccess()) {
                     throw new Main\SystemException('Cannot create location');
                 }
                 $descriptior['CODES'][$item['CODE']] = $res->getId();
             }
         }
         if (!count($block)) {
             unset($descriptior['CODES']);
             $descriptior['STEP'] = 'rebalance';
         }
     }
     return $descriptior['STEP'] == 'done';
 }
예제 #3
0
				try
				{
					$res = Helper::delete($id, true);
					if(!$res['success'])
						throw new Main\SystemException(Loc::getMessage('SALE_LOCATION_L_ITEM').' '.$id.' : '.implode('<br />', $res['errors']));
					$DB->Commit();
				}
				catch(Main\SystemException $e)
				{
					$lAdmin->AddGroupError(Loc::getMessage('SALE_LOCATION_L_ITEM_DELETE_ERROR').": <br /><br />".$e->getMessage(), $id);
					$DB->Rollback();
				}
			}
		}

		Location\LocationTable::resetLegacyPath();
	}

	$adminResult = Helper::getList($listParams, $sTableID);
	$lAdmin->NavText($adminResult->GetNavPrint(Loc::getMessage('SALE_LOCATION_L_PAGES'), true)); // do not relocate the call relative to DisplayList(), or you`ll catch a strange nav bar disapper bug
}
catch(Main\SystemException $e)
{
	$code = $e->getCode();
	$fatal = $e->getMessage().(!empty($code) ? ' ('.$code.')' : '');
}

#####################################
#### PAGE INTERFACE GENERATION
#####################################
예제 #4
0
 public static function resetLegacyPath()
 {
     Helper::dropTable(self::TABLE_LEGACY_RELATIONS);
     $dbConnection = \Bitrix\Main\HttpApplication::getConnection();
     $dbConnection->query("create table " . self::TABLE_LEGACY_RELATIONS . " (\n\t\t\tID " . Helper::getSqlForDataType('int') . ",\n\t\t\tCOUNTRY_ID " . Helper::getSqlForDataType('int') . ",\n\t\t\tREGION_ID " . Helper::getSqlForDataType('int') . ",\n\t\t\tCITY_ID " . Helper::getSqlForDataType('int') . "\n\t\t)");
     $dbConnection->query("insert into " . self::TABLE_LEGACY_RELATIONS . " (ID, COUNTRY_ID, REGION_ID, CITY_ID) select ID, COUNTRY_ID, REGION_ID, CITY_ID from b_sale_location");
     Location\LocationTable::resetLegacyPath();
 }
예제 #5
0
	protected function stageRestoreIndexes()
	{
		$indexes = array(
			'IX_B_SALE_LOC_MARGINS',
			'IX_B_SALE_LOC_MARGINS_REV',
			//'IX_B_SALE_LOC_PARENT', // already restored at REBALANCE_WALK_TREE stage
			'IX_B_SALE_LOC_DL',
			'IX_B_SALE_LOC_TYPE',
			'IX_B_SALE_LOC_NAME_NAME_U',
			'IX_B_SALE_LOC_NAME_LI_LI',
			'IX_B_SALE_LOC_EXT_LID_SID',

			// old
			'IXS_LOCATION_COUNTRY_ID',
			'IXS_LOCATION_REGION_ID',
			'IXS_LOCATION_CITY_ID',
		);

		if(isset($indexes[$this->getStep()]))
		{
			$this->restoreIndexes($indexes[$this->getStep()]);
			$this->logMessage('Index restored: '.$indexes[$this->getStep()]);
			$this->nextStep();
		}
		else
		{
			Location\LocationTable::resetLegacyPath(); // for backward compatibility
			$this->nextStage();
		}
	}