Exemplo n.º 1
0
 private static function proxyToDisk($methodName, array $args = array())
 {
     if (!(\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::includeModule('disk'))) {
         return;
     }
     //call_user_func don't like &
     if (strtolower($methodName) == 'getfieldinputvalue') {
         list($documentType, $fieldType, $fieldName, $request, $errors) = $args;
         return \Bitrix\Disk\BizProcDocumentCompatible::getFieldInputValue($documentType, $fieldType, $fieldName, $request, $errors);
     }
     if (strtolower($methodName) == 'getfieldinputcontroloptions') {
         list($documentType, $arFieldType, $jsFunctionName, $value) = $args;
         return \Bitrix\Disk\BizProcDocumentCompatible::getFieldInputControlOptions($documentType, $arFieldType, $jsFunctionName, $value);
     }
     $className = \Bitrix\Disk\BizProcDocumentCompatible::className();
     return call_user_func_array(array($className, $methodName), $args);
 }
 protected function migrateDataCommonStorages()
 {
     if ($this->isStepFinished(__METHOD__)) {
         return array(0, 0);
     }
     $lastId = $this->getLastIblockId();
     if ($this->isOracle && $lastId == 0) {
         //we support 10g : (
         $maxId = $this->connection->queryScalar('SELECT MAX(ID) MAX FROM b_disk_object');
         $maxId++;
         $seqId = $this->connection->query('SELECT sq_b_disk_object.NEXTVAL NEXTVAL FROM DUAL')->fetch();
         $seqId = $seqId['NEXTVAL'];
         $diffId = $maxId - $seqId;
         if ($diffId > 0) {
             $this->connection->queryExecute("ALTER SEQUENCE sq_b_disk_object INCREMENT BY {$diffId}");
             $this->connection->queryExecute("SELECT sq_b_disk_object.NEXTVAL NEXTVAL FROM DUAL");
             $this->connection->queryExecute("ALTER SEQUENCE sq_b_disk_object INCREMENT BY 1");
         }
     }
     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']);
         $proxyType = $sqlHelper->forSql(ProxyType\Common::className());
         $storageRow = $this->connection->query("SELECT * FROM b_disk_storage WHERE XML_ID = '{$iblockId}' AND ENTITY_TYPE = '{$proxyType}'")->fetch();
         if (!$storageRow) {
             $this->log(array(__METHOD__, 'Error. Could not find storage by XML_ID', $iblock['ID'], "WHERE XML_ID = '{$iblockId}' AND ENTITY_TYPE = '{$proxyType}'"));
             $this->storeIblockId($iblock['ID']);
             continue;
         }
         $storageId = $storageRow['ID'];
         $this->connection->queryExecute("\n\t\t\t\tINSERT INTO b_disk_object (NAME, TYPE, CODE, STORAGE_ID, PARENT_ID, CREATE_TIME, UPDATE_TIME, WEBDAV_IBLOCK_ID)\n\t\t\t\tSELECT '{$name}', 2, null, {$storageId}, null, ib.TIMESTAMP_X, ib.TIMESTAMP_X, ib.ID FROM b_iblock ib WHERE ib.ID = {$iblockId}\n\n\t\t\t");
         $rootObjectId = null;
         if ($this->isMysql || $this->isMssql) {
             $rootObjectId = (int) $this->connection->getInsertedId();
         } elseif ($this->isOracle) {
             $rootObjectId = $this->connection->queryScalar('SELECT MAX(ID) MAX FROM b_disk_object');
         }
         if (!$rootObjectId) {
             $this->log(array(__METHOD__, 'Error. Could not insert root object', array($name, $storageId, $iblockId)));
             $this->storeIblockId($iblock['ID']);
             continue;
         }
         if ($this->isMysql) {
             $sql = "\n\t\t\t\t\tUPDATE b_disk_object do,\n\t\t\t\t\t(\n\t\t\t\t\t\tSELECT NAME, MIN(ID) ID, COUNT(*) C\n\t\t\t\t\t\tFROM b_disk_object\n\t\t\t\t\t\tWHERE STORAGE_ID = {$storageId} AND PARENT_ID IS NULL AND ID <> {$rootObjectId}\n\t\t\t\t\t\tGROUP BY NAME\n\t\t\t\t\t\tHAVING C>1\n\t\t\t\t\t) dbl\n\t\t\t\t\tSET do.NAME = " . $this->getConcatFunction('do.NAME', 'do.ID') . "\n\t\t\t\t\tWHERE do.STORAGE_ID = {$storageId} AND do.PARENT_ID IS NULL AND do.ID <> {$rootObjectId}\n\t\t\t\t\t\tAND do.ID > dbl.ID\n\t\t\t\t\t\tAND do.NAME=dbl.NAME\n\t\t\t\t";
         } elseif ($this->isOracle || $this->isMssql) {
             $sql = "\n\t\t\t\t\tUPDATE b_disk_object\n\t\t\t\t\t\tSET NAME = (\n\t\t\t\t\t\t\tSELECT " . $this->getConcatFunction('do.NAME', 'do.ID') . " FROM b_disk_object do,\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tSELECT NAME, MIN(ID) ID, COUNT(*) C\n\t\t\t\t\t\t\t\tFROM b_disk_object\n\t\t\t\t\t\t\t\tWHERE STORAGE_ID = {$storageId} AND PARENT_ID IS NULL AND ID <> {$rootObjectId}\n\t\t\t\t\t\t\t\tGROUP BY NAME\n\t\t\t\t\t\t\t\tHAVING COUNT(*)>1\n\t\t\t\t\t\t\t) dbl\n\t\t\t\t\t\t\tWHERE do.STORAGE_ID = {$storageId} AND do.PARENT_ID IS NULL AND do.ID <> {$rootObjectId}\n\t\t\t\t\t\t\t\tAND do.ID > dbl.ID\n\t\t\t\t\t\t\t\tAND do.NAME=dbl.NAME\n\t\t\t\t\t\t\t\tAND b_disk_object.ID = do.ID\n\t\t\t\t\t\t)\n\n\t\t\t\t\t\tWHERE EXISTS (\n\t\t\t\t\t\t\tSELECT " . $this->getConcatFunction('do.NAME', 'do.ID') . " FROM b_disk_object do,\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tSELECT NAME, MIN(ID) ID, COUNT(*) C\n\t\t\t\t\t\t\t\tFROM b_disk_object\n\t\t\t\t\t\t\t\tWHERE STORAGE_ID = {$storageId} AND PARENT_ID IS NULL AND ID <> {$rootObjectId}\n\t\t\t\t\t\t\t\tGROUP BY NAME\n\t\t\t\t\t\t\t\tHAVING COUNT(*)>1\n\t\t\t\t\t\t\t) dbl\n\t\t\t\t\t\t\tWHERE do.STORAGE_ID = {$storageId} AND do.PARENT_ID IS NULL AND do.ID <> {$rootObjectId}\n\t\t\t\t\t\t\t\tAND do.ID > dbl.ID\n\t\t\t\t\t\t\t\tAND do.NAME=dbl.NAME\n\t\t\t\t\t\t\t\tAND b_disk_object.ID = do.ID\n\t\t\t\t\t\t)\n\t\t\t\t";
         }
         $this->connection->queryExecute($sql);
         $this->connection->queryExecute("\n\t\t\t\tUPDATE b_disk_object SET PARENT_ID = {$rootObjectId} WHERE STORAGE_ID = {$storageId} AND PARENT_ID IS NULL AND ID <> {$rootObjectId}\n\t\t\t");
         $this->connection->queryExecute("\n\t\t\t\tUPDATE b_disk_storage SET ROOT_OBJECT_ID = {$rootObjectId} WHERE ID = {$storageId}\n\t\t\t");
         $this->moveCommonElements($storageId, $rootObjectId, $iblock);
         if ($this->runWorkWithBizproc) {
             $classDocument = $this->sqlHelper->forSql(\Bitrix\Disk\BizProcDocumentCompatible::className());
             if ($this->isMssql || $this->isMysql) {
                 $this->connection->queryExecute("\n\t\t\t\t\t\tINSERT INTO b_bp_workflow_template (MODULE_ID, ENTITY, DOCUMENT_TYPE, AUTO_EXECUTE, NAME, DESCRIPTION, TEMPLATE, PARAMETERS, VARIABLES, MODIFIED, USER_ID, SYSTEM_CODE, ACTIVE)\n\t\t\t\t\t\tSELECT 'disk', '{$classDocument}', 'STORAGE_{$storageId}', AUTO_EXECUTE, NAME, DESCRIPTION, TEMPLATE, PARAMETERS, VARIABLES, MODIFIED, USER_ID, SYSTEM_CODE, ACTIVE\n\t\t\t\t\t\t\tFROM b_bp_workflow_template\n\t\t\t\t\t\t\tWHERE MODULE_ID = 'webdav' AND ENTITY = 'CIBlockDocumentWebdav' AND DOCUMENT_TYPE = 'iblock_{$iblock['ID']}'\n\t\t\t\t\t");
             } elseif ($this->isOracle) {
                 $this->connection->queryExecute("\n\t\t\t\t\t\tINSERT INTO b_bp_workflow_template (ID, MODULE_ID, ENTITY, DOCUMENT_TYPE, AUTO_EXECUTE, NAME, DESCRIPTION, TEMPLATE, PARAMETERS, VARIABLES, MODIFIED, USER_ID, SYSTEM_CODE, ACTIVE)\n\t\t\t\t\t\tSELECT SQ_B_BP_WORKFLOW_TEMPLATE.nextval, 'disk', '{$classDocument}', 'STORAGE_{$storageId}', AUTO_EXECUTE, NAME, DESCRIPTION, TEMPLATE, PARAMETERS, VARIABLES, MODIFIED, USER_ID, SYSTEM_CODE, ACTIVE\n\t\t\t\t\t\t\tFROM b_bp_workflow_template\n\t\t\t\t\t\t\tWHERE MODULE_ID = 'webdav' AND ENTITY = 'CIBlockDocumentWebdav' AND DOCUMENT_TYPE = 'iblock_{$iblock['ID']}'\n\t\t\t\t\t");
             }
         }
         $this->log(array(__METHOD__, 'finish', $iblock['ID']));
         $this->storeIblockId($iblock['ID']);
     }
     $this->storeIblockId(0);
     $this->setStepFinished(__METHOD__);
 }