コード例 #1
0
 protected function migrateVersion()
 {
     if (!$this->runWorkWithBizproc) {
         return;
     }
     if ($this->isStepFinished(__METHOD__)) {
         return;
     }
     $uploadDir = COption::getOptionString("main", "upload_dir", "upload");
     $isCloud = CModule::IncludeModule("clouds");
     $useGZipCompressionOption = \Bitrix\Main\Config\Option::get("bizproc", "use_gzip_compression", "");
     $isBitrix24 = IsModuleInstalled('bitrix24');
     $bucket = null;
     if ($isBitrix24 && $isCloud) {
         $bucket = new CCloudStorageBucket(1);
         $bucket->init();
     }
     if ($useGZipCompressionOption === "Y") {
         $this->useGZipCompression = true;
     } elseif ($useGZipCompressionOption === "N") {
         $this->useGZipCompression = false;
     } else {
         $this->useGZipCompression = function_exists("gzcompress") && ($GLOBALS["DB"]->type != "ORACLE" || !defined('BX_UTF'));
     }
     $sqlHelper = $this->connection->getSqlHelper();
     $lastId = $this->getStorageId();
     $versionQuery = $this->connection->query("\n\t\t\tSELECT\n\t\t\t\tobj.*,\n\t\t\t\th.ID VERSION_ID,\n\t\t\t\th.NAME VERSION_NAME,\n\t\t\t\th.DOCUMENT VERSION_DOC,\n\t\t\t\th.USER_ID VERSION_USER_ID,\n\t\t\t\th.MODIFIED VERSION_MODIFIED\n\t\t\tFROM b_disk_object obj\n\t\t\t\tINNER JOIN b_bp_history h ON h.DOCUMENT_ID = obj.WEBDAV_ELEMENT_ID AND h.MODULE_ID = 'webdav'\n\n\t\t\tWHERE obj.TYPE = 3 AND h.ID > {$lastId} ORDER BY h.ID\n\t\t");
     while ($version = $versionQuery->fetch()) {
         $this->abortIfNeeded();
         if (strlen($version['VERSION_DOC']) > 0) {
             if ($this->useGZipCompression) {
                 $version['VERSION_DOC'] = gzuncompress($version['VERSION_DOC']);
             }
             $version['VERSION_DOC'] = unserialize($version['VERSION_DOC']);
             if (!is_array($version['VERSION_DOC'])) {
                 $version['VERSION_DOC'] = array();
             }
         } else {
             $version['VERSION_DOC'] = array();
         }
         if (empty($version['VERSION_DOC']) || empty($version['VERSION_DOC']['PROPERTIES']['WEBDAV_VERSION']['VALUE']) || empty($version['VERSION_DOC']['PROPERTIES']['FILE']['VALUE'])) {
             $this->storeStorageId($version['VERSION_ID']);
             continue;
         }
         $version['VERSION_NAME'] = $sqlHelper->forSql($version['VERSION_NAME']);
         $version['VERSION_MODIFIED'] = $sqlHelper->getCharToDateFunction($version['VERSION_MODIFIED']->format("Y-m-d H:i:s"));
         $version['UPDATE_TIME'] = $sqlHelper->getCharToDateFunction($version['UPDATE_TIME']->format("Y-m-d H:i:s"));
         $fullPath = $version['VERSION_DOC']['PROPERTIES']['FILE']['VALUE'];
         $handlerId = '';
         $filename = bx_basename($fullPath);
         if (substr($fullPath, 0, 4) == "http") {
             if (!$isCloud) {
                 $this->storeStorageId($version['VERSION_ID']);
                 continue;
             }
             if (!$isBitrix24) {
                 $bucket = CCloudStorage::findBucketByFile($fullPath);
                 if (!$bucket) {
                     $this->storeStorageId($version['VERSION_ID']);
                     continue;
                 }
             }
             $handlerId = $bucket->ID;
             $subDir = trim(substr(getDirPath($fullPath), strlen($bucket->getFileSRC('/'))), '/');
             $contentType = \Bitrix\Disk\TypeFile::getMimeTypeByFilename($filename);
         } else {
             $subDir = trim(substr(getDirPath($fullPath), strlen('/' . $uploadDir)), '/');
             $contentType = CFile::getContentType($_SERVER["DOCUMENT_ROOT"] . $fullPath);
             $contentType = \Bitrix\Disk\TypeFile::normalizeMimeType($contentType, $filename);
         }
         $webdavSize = $version['VERSION_DOC']['PROPERTIES']['WEBDAV_SIZE']['VALUE'];
         if (empty($webdavSize)) {
             $webdavSize = 0;
         }
         $fileId = CFile::doInsert(array('HEIGHT' => 0, 'WIDTH' => 0, 'FILE_SIZE' => $webdavSize, 'CONTENT_TYPE' => $contentType, 'SUBDIR' => $subDir, 'FILE_NAME' => $filename, 'MODULE_ID' => Driver::INTERNAL_MODULE_ID, 'ORIGINAL_NAME' => $filename, 'DESCRIPTION' => '', 'HANDLER_ID' => $handlerId, 'EXTERNAL_ID' => md5(mt_rand())));
         if (!$fileId) {
             $this->storeStorageId($version['VERSION_ID']);
             continue;
         }
         $this->connection->queryExecute("\n\t\t\t\tINSERT INTO b_disk_version (OBJECT_ID, FILE_ID, " . $this->sqlHelper->quote('SIZE') . ", NAME, CREATE_TIME, CREATED_BY, MISC_DATA, OBJECT_CREATE_TIME, OBJECT_CREATED_BY, OBJECT_UPDATE_TIME, OBJECT_UPDATED_BY, GLOBAL_CONTENT_VERSION, BP_VERSION_ID)\n\t\t\t\tVALUES ({$version['ID']}, {$fileId}, {$webdavSize}, '{$version['VERSION_NAME']}', {$version['VERSION_MODIFIED']},  {$version['VERSION_USER_ID']}, null, {$version['VERSION_MODIFIED']}, {$version['CREATED_BY']}, {$version['UPDATE_TIME']}, {$version['UPDATED_BY']}, {$version['VERSION_DOC']['PROPERTIES']['WEBDAV_VERSION']['VALUE']}, {$version['VERSION_ID']})\n\t\t\t");
         $this->storeStorageId($version['VERSION_ID']);
     }
     $this->abortIfNeeded();
     $this->storeStorageId(0);
     $this->setStepFinished(__METHOD__);
 }