protected function moveStructureCommonStorages()
 {
     if ($this->isStepFinished(__METHOD__)) {
         return array(0, 0);
     }
     $storageIdToIblock = array();
     $lastId = $this->getLastIblockId();
     foreach ($this->getIblockIdsWithCommonFiles() as $iblock) {
         if ($lastId > $iblock['ID']) {
             continue;
         }
         $this->abortIfNeeded();
         $this->log(array(__METHOD__, 'start', $iblock['ID']));
         $iblockId = (int) $iblock['ID'];
         $sqlHelper = $this->connection->getSqlHelper();
         $name = $sqlHelper->forSql($iblock['NAME']);
         $siteId = $sqlHelper->forSql($iblock['LID']);
         $proxyType = $sqlHelper->forSql(ProxyType\Common::className());
         $entityId = $sqlHelper->forSql($iblock['CODE'] == 'shared_files' ? 'shared_files_s1' : ($iblock['CODE'] ?: $iblock['ID']));
         if (empty($entityId)) {
             $entityId = 'iblock' . $iblockId;
         }
         $miscData = $sqlHelper->forSql(serialize(array('BASE_URL' => $iblock['LIST_PAGE_URL'], 'BIZPROC_ENABLED' => $iblock['BIZPROC'] == 'Y')));
         $this->connection->queryExecute("\n\t\t\t\tINSERT INTO b_disk_storage (NAME, MODULE_ID, ENTITY_TYPE, ENTITY_ID, ENTITY_MISC_DATA, ROOT_OBJECT_ID, USE_INTERNAL_RIGHTS, SITE_ID, XML_ID)\n\t\t\t\tVALUES ('{$name}', 'disk', '{$proxyType}', '{$entityId}', '{$miscData}', null, 1, '{$siteId}', '{$iblockId}')\n\t\t\t");
         $storageId = null;
         if ($this->isMysql || $this->isMssql) {
             $storageId = (int) $this->connection->getInsertedId();
         } elseif ($this->isOracle) {
             $storageId = $this->connection->queryScalar('SELECT MAX(ID) MAX FROM b_disk_storage');
         }
         if (!$storageId) {
             $this->log(array(__METHOD__, 'Error. Could not insert storage', "\n\t\t\t\tINSERT INTO b_disk_storage (NAME, MODULE_ID, ENTITY_TYPE, ENTITY_ID, ENTITY_MISC_DATA, ROOT_OBJECT_ID, USE_INTERNAL_RIGHTS, SITE_ID, XML_ID)\n\t\t\t\tVALUES ('{$name}', 'disk', '{$proxyType}', '{$entityId}', '{$miscData}', null, 1, '{$siteId}', '{$iblockId}')\n\t\t\t", array("('{$name}', 'disk', '{$proxyType}', '{$entityId}', '{$miscData}', null, 1, '{$siteId}', '{$iblockId}')")));
             $this->storeIblockId($iblock['ID']);
             continue;
         }
         $storageIdToIblock[$storageId] = $iblock;
         //I know: child.IBLOCK_SECTION_ID can be NULL. But it is possible - unique key (NAME, PARENT_ID)
         if ($this->isMysql) {
             $sql = "\n\t\t\t\t\tINSERT IGNORE INTO b_disk_object (ID, REAL_OBJECT_ID, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_SECTION_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\t\tSELECT child.ID, child.ID, child.NAME, 2, child.CODE, {$storageId}, child.IBLOCK_SECTION_ID, child.DATE_CREATE, " . $this->sqlHelper->getIsNullFunction('child.TIMESTAMP_X', 'child.DATE_CREATE') . ", " . $this->sqlHelper->getIsNullFunction('child.CREATED_BY', 0) . ", child.MODIFIED_BY, child.ID, child.ID, child.IBLOCK_ID\n\t\t\t\t\t\tFROM b_iblock_section child\n\t\t\t\t\t\tWHERE child.IBLOCK_ID = {$iblockId}\n\n\t\t\t\t";
         } elseif ($this->isOracle || $this->isMssql) {
             $sql = "\n\t\t\t\t\tINSERT INTO b_disk_object (ID, REAL_OBJECT_ID, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_SECTION_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\t\tSELECT child.ID, child.ID, child.NAME, 2, child.CODE, {$storageId}, child.IBLOCK_SECTION_ID, child.DATE_CREATE, " . $this->sqlHelper->getIsNullFunction('child.TIMESTAMP_X', 'child.DATE_CREATE') . ", " . $this->sqlHelper->getIsNullFunction('child.CREATED_BY', 0) . ", child.MODIFIED_BY, child.ID, child.ID, child.IBLOCK_ID\n\t\t\t\t\t\tFROM b_iblock_section child\n\t\t\t\t\t\tWHERE child.IBLOCK_ID = {$iblockId}\n\t\t\t\t\t\t\tAND NOT EXISTS(SELECT 'x' FROM b_disk_object WHERE NAME = child.NAME AND PARENT_ID = child.IBLOCK_SECTION_ID AND child.IBLOCK_SECTION_ID IS NOT NULL)\n\t\t\t\t";
         }
         if ($this->isMssql) {
             $this->connection->queryExecute('SET IDENTITY_INSERT b_disk_object ON');
         }
         $this->connection->queryExecute($sql);
         $this->connection->queryExecute("\n\t\t\t\tINSERT INTO b_disk_object (ID, REAL_OBJECT_ID, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_SECTION_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\tSELECT child.ID, child.ID, " . $this->getConcatFunction('child.NAME', 'child.ID') . ", 2, child.CODE, {$storageId}, child.IBLOCK_SECTION_ID, child.DATE_CREATE, " . $this->sqlHelper->getIsNullFunction('child.TIMESTAMP_X', 'child.DATE_CREATE') . ", " . $this->sqlHelper->getIsNullFunction('child.CREATED_BY', 0) . ", child.MODIFIED_BY, child.ID, child.ID, child.IBLOCK_ID\n\t\t\t\tFROM b_iblock_section child\n\t\t\t\tWHERE child.IBLOCK_ID = {$iblockId} AND NOT EXISTS(SELECT 'x' FROM b_disk_object do WHERE do.ID=child.ID)\n\t\t\t");
         if ($this->isMssql) {
             $this->connection->queryExecute('SET IDENTITY_INSERT b_disk_object OFF');
         }
         $this->log(array(__METHOD__, 'finish', $iblock['ID']));
         $this->storeIblockId($iblock['ID']);
     }
     unset($iblock);
     $this->storeIblockId(0);
     $this->setStepFinished(__METHOD__);
 }