Beispiel #1
0
 /**
  * Returns quoted identifier.
  *
  * @param string $identifier Table or Column name.
  *
  * @return string
  * @see \Bitrix\Main\DB\SqlHelper::quote
  */
 public function quote($identifier)
 {
     return parent::quote(strtoupper($identifier));
 }
 private function moveCommonElements($storageId, $rootObjectId, $iblock)
 {
     $iblockId = $iblock['ID'];
     $sqlHelper = $this->connection->getSqlHelper();
     if ($iblock['VERSION'] == 2) {
         $props = $this->connection->query("SELECT * FROM b_iblock_property WHERE VERSION = 2 AND IBLOCK_ID = {$iblockId} AND CODE IN ('WEBDAV_SIZE', 'FILE', 'WEBDAV_VERSION')")->fetchAll();
         $joinTable = 'b_iblock_element_prop_s' . $iblockId;
         $columnForFileId = $columnForSize = 'null';
         $columnForVersion = '1';
         foreach ($props as $prop) {
             switch ($prop['CODE']) {
                 case 'WEBDAV_SIZE':
                     $columnForSize = 'PROPERTY_' . $prop['ID'];
                     break;
                 case 'FILE':
                     $columnForFileId = 'PROPERTY_' . $prop['ID'];
                     break;
                 case 'WEBDAV_VERSION':
                     $columnForVersion = 'PROPERTY_' . $prop['ID'];
                     break;
             }
         }
         unset($prop);
         if ($this->isMysql) {
             $sql = "\n\t\t\t\t\t\tINSERT IGNORE INTO b_disk_object (FILE_ID, SIZE, GLOBAL_CONTENT_VERSION, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_ELEMENT_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\t\t\tSELECT {$columnForFileId}, {$columnForSize}, {$columnForVersion}, child.NAME, 3, null, {$storageId}, " . $sqlHelper->getIsNullFunction('child.IBLOCK_SECTION_ID', $rootObjectId) . ", 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   FROM b_iblock_element child\n\n\t\t\t\t\t\tINNER JOIN {$joinTable} props ON props.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\t\tWHERE child.IBLOCK_ID = {$iblockId} AND child.IBLOCK_SECTION_ID IS NULL\n\t\t\t\t\t";
         } elseif ($this->isOracle || $this->isMssql) {
             $sql = "\n\t\t\t\t\t\tINSERT INTO b_disk_object (FILE_ID, " . $this->sqlHelper->quote('SIZE') . ", GLOBAL_CONTENT_VERSION, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_ELEMENT_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\t\t\tSELECT {$columnForFileId}, {$columnForSize}, {$columnForVersion}, child.NAME, 3, null, {$storageId}, " . $sqlHelper->getIsNullFunction('child.IBLOCK_SECTION_ID', $rootObjectId) . ", 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   FROM b_iblock_element child\n\n\t\t\t\t\t\tINNER JOIN {$joinTable} props ON props.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\t\tWHERE child.IBLOCK_ID = {$iblockId} AND child.IBLOCK_SECTION_ID IS NULL\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\t";
         }
         $this->connection->queryExecute($sql);
         $this->connection->queryExecute("\n\t\t\t\t\tINSERT INTO b_disk_object (FILE_ID, " . $this->sqlHelper->quote('SIZE') . ", GLOBAL_CONTENT_VERSION, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_ELEMENT_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\t\tSELECT {$columnForFileId}, {$columnForSize}, {$columnForVersion}, " . $this->getConcatFunction('child.ID', 'child.NAME') . ", 3, null, {$storageId}, " . $sqlHelper->getIsNullFunction('child.IBLOCK_SECTION_ID', $rootObjectId) . ", 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   FROM b_iblock_element child\n\n\t\t\t\t\tINNER JOIN {$joinTable} props ON props.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tchild.IBLOCK_ID = {$iblockId} AND child.IBLOCK_SECTION_ID IS NULL\n\t\t\t\t\t\tAND NOT EXISTS(SELECT 'x' FROM b_disk_object do WHERE do.WEBDAV_ELEMENT_ID=child.ID)\n\n\t\t\t\t");
     } else {
         if ($this->isMysql) {
             $sql = "\n\t\t\t\t\t\tINSERT IGNORE INTO b_disk_object (FILE_ID, SIZE, GLOBAL_CONTENT_VERSION, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_ELEMENT_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\t\t\tSELECT PROP_FILE_EL.VALUE, PROP_SIZE_EL.VALUE, " . $sqlHelper->getIsNullFunction('PPROP_VERSION_G_EL.VALUE', 1) . ", child.NAME, 3, null, {$storageId}, " . $sqlHelper->getIsNullFunction('child.IBLOCK_SECTION_ID', $rootObjectId) . ", 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   FROM b_iblock_element child\n\n\t\t\t\t\t\tINNER JOIN b_iblock_property PROP_SIZE ON PROP_SIZE.IBLOCK_ID = child.IBLOCK_ID AND PROP_SIZE.CODE = 'WEBDAV_SIZE'\n\t\t\t\t\t\tINNER JOIN b_iblock_element_property PROP_SIZE_EL ON PROP_SIZE_EL.IBLOCK_PROPERTY_ID = PROP_SIZE.ID AND PROP_SIZE_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\t\tINNER JOIN b_iblock_property PROP_FILE ON PROP_FILE.IBLOCK_ID = child.IBLOCK_ID AND PROP_FILE.CODE = 'FILE'\n\t\t\t\t\t\tINNER JOIN b_iblock_element_property PROP_FILE_EL ON PROP_FILE_EL.IBLOCK_PROPERTY_ID = PROP_FILE.ID AND PROP_FILE_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\t\tLEFT JOIN b_iblock_property PROP_VERSION_G ON PROP_VERSION_G.IBLOCK_ID = child.IBLOCK_ID AND PROP_VERSION_G.CODE = 'WEBDAV_VERSION'\n\t\t\t\t\t\tLEFT JOIN b_iblock_element_property PPROP_VERSION_G_EL ON PPROP_VERSION_G_EL.IBLOCK_PROPERTY_ID = PROP_VERSION_G.ID AND PPROP_VERSION_G_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\t\tWHERE child.IBLOCK_ID = {$iblockId} AND child.IBLOCK_SECTION_ID IS NULL\n\t\t\t\t\t";
         } elseif ($this->isOracle || $this->isMssql) {
             $sql = "\n\t\t\t\t\t\tINSERT INTO b_disk_object (FILE_ID, " . $this->sqlHelper->quote('SIZE') . ", GLOBAL_CONTENT_VERSION, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_ELEMENT_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\t\t\tSELECT PROP_FILE_EL.VALUE, PROP_SIZE_EL.VALUE, " . $sqlHelper->getIsNullFunction('PPROP_VERSION_G_EL.VALUE', 1) . ", child.NAME, 3, null, {$storageId}, " . $sqlHelper->getIsNullFunction('child.IBLOCK_SECTION_ID', $rootObjectId) . ", 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   FROM b_iblock_element child\n\n\t\t\t\t\t\tINNER JOIN b_iblock_property PROP_SIZE ON PROP_SIZE.IBLOCK_ID = child.IBLOCK_ID AND PROP_SIZE.CODE = 'WEBDAV_SIZE'\n\t\t\t\t\t\tINNER JOIN b_iblock_element_property PROP_SIZE_EL ON PROP_SIZE_EL.IBLOCK_PROPERTY_ID = PROP_SIZE.ID AND PROP_SIZE_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\t\tINNER JOIN b_iblock_property PROP_FILE ON PROP_FILE.IBLOCK_ID = child.IBLOCK_ID AND PROP_FILE.CODE = 'FILE'\n\t\t\t\t\t\tINNER JOIN b_iblock_element_property PROP_FILE_EL ON PROP_FILE_EL.IBLOCK_PROPERTY_ID = PROP_FILE.ID AND PROP_FILE_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\t\tLEFT JOIN b_iblock_property PROP_VERSION_G ON PROP_VERSION_G.IBLOCK_ID = child.IBLOCK_ID AND PROP_VERSION_G.CODE = 'WEBDAV_VERSION'\n\t\t\t\t\t\tLEFT JOIN b_iblock_element_property PPROP_VERSION_G_EL ON PPROP_VERSION_G_EL.IBLOCK_PROPERTY_ID = PROP_VERSION_G.ID AND PPROP_VERSION_G_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\t\tWHERE child.IBLOCK_ID = {$iblockId} AND child.IBLOCK_SECTION_ID IS NULL\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\t";
         }
         $this->connection->queryExecute($sql);
         $this->connection->queryExecute("\n\t\t\t\t\tINSERT INTO b_disk_object (FILE_ID, " . $this->sqlHelper->quote('SIZE') . ", GLOBAL_CONTENT_VERSION, NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, CREATED_BY, UPDATED_BY, XML_ID, WEBDAV_ELEMENT_ID, WEBDAV_IBLOCK_ID)\n\t\t\t\t\tSELECT PROP_FILE_EL.VALUE, PROP_SIZE_EL.VALUE, " . $sqlHelper->getIsNullFunction('PPROP_VERSION_G_EL.VALUE', 1) . ", " . $this->getConcatFunction('child.ID', 'child.NAME') . ", 3, null, {$storageId}, " . $sqlHelper->getIsNullFunction('child.IBLOCK_SECTION_ID', $rootObjectId) . ", 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   FROM b_iblock_element child\n\n\t\t\t\t\tINNER JOIN b_iblock_property PROP_SIZE ON PROP_SIZE.IBLOCK_ID = child.IBLOCK_ID AND PROP_SIZE.CODE = 'WEBDAV_SIZE'\n\t\t\t\t\tINNER JOIN b_iblock_element_property PROP_SIZE_EL ON PROP_SIZE_EL.IBLOCK_PROPERTY_ID = PROP_SIZE.ID AND PROP_SIZE_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\tINNER JOIN b_iblock_property PROP_FILE ON PROP_FILE.IBLOCK_ID = child.IBLOCK_ID AND PROP_FILE.CODE = 'FILE'\n\t\t\t\t\tINNER JOIN b_iblock_element_property PROP_FILE_EL ON PROP_FILE_EL.IBLOCK_PROPERTY_ID = PROP_FILE.ID AND PROP_FILE_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\tLEFT JOIN b_iblock_property PROP_VERSION_G ON PROP_VERSION_G.IBLOCK_ID = child.IBLOCK_ID AND PROP_VERSION_G.CODE = 'WEBDAV_VERSION'\n\t\t\t\t\tLEFT JOIN b_iblock_element_property PPROP_VERSION_G_EL ON PPROP_VERSION_G_EL.IBLOCK_PROPERTY_ID = PROP_VERSION_G.ID AND PPROP_VERSION_G_EL.IBLOCK_ELEMENT_ID = child.ID\n\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tchild.IBLOCK_ID = {$iblockId} AND child.IBLOCK_SECTION_ID IS NULL\n\t\t\t\t\t\tAND NOT EXISTS(SELECT 'x' FROM b_disk_object do WHERE do.WEBDAV_ELEMENT_ID=child.ID)\n\n\t\t\t\t");
     }
 }