Exemplo n.º 1
0
 /**
  * Gets all fields (DataManager fields).
  * @return array
  */
 public function getDataManagerFields()
 {
     return ExternalLinkTable::getMap();
 }
Exemplo n.º 2
0
 /**
  * Gets the fully qualified name of table class which belongs to current model.
  * @throws \Bitrix\Main\NotImplementedException
  * @return string
  */
 public static function getTableClassName()
 {
     return ExternalLinkTable::className();
 }
 protected function migrateExternalLinks()
 {
     $this->abortIfNeeded();
     if ($this->isStepFinished(__METHOD__)) {
         return array(0, 0);
     }
     $successCount = $failedCount = 0;
     $this->log(array('Start migrate external links'));
     $lastCreationDate = $this->getLastConvertedExtLinkCreationDate();
     $connection = Application::getInstance()->getConnection();
     $query = $connection->query("\n\t\t\tSELECT * from b_webdav_ext_links ext\n\t\t\tWHERE ext.LINK_TYPE = 'M' AND ext.RESOURCE_TYPE = 'IBLOCK' AND ext.CREATION_DATE > {$lastCreationDate} AND (ext.ELEMENT_ID IS NULL OR ext.ELEMENT_ID = 0)\n\t\t\tORDER BY ext.CREATION_DATE\n\t\t");
     while ($query && ($extLinkRow = $query->fetch())) {
         $this->abortIfNeeded();
         $extLinkData = $this->prepareDataFromOldExtLink($extLinkRow);
         if (empty($extLinkRow['ROOT_SECTION_ID']) && !empty($extLinkRow['URL'])) {
             $this->log(array('Migrate simple ext.link from common storage (without symbolic link)'));
             $success = true;
             $pathItems = explode('/', ltrim($extLinkRow['URL'], '/'));
             $nameOfElement = array_pop($pathItems);
             $prevSectionId = 0;
             $prevIblockId = $extLinkRow['IBLOCK_ID'];
             foreach ($pathItems as $path) {
                 $pathFilter = array('=NAME' => $path, 'IBLOCK_ID' => $prevIblockId, 'SECTION_ID' => $prevSectionId);
                 $section = CIBlockSection::getList(array(), $pathFilter, false, array('ID', 'IBLOCK_ID'))->fetch();
                 if (!$section) {
                     $success = false;
                     break;
                 }
                 $prevSectionId = $section['ID'];
                 $prevIblockId = $section['IBLOCK_ID'];
             }
             unset($path);
             if (!$success) {
                 $this->log(array('Could not migrate ext.link (resolve path)', $extLinkRow));
                 $this->storeConvertedExtLinkCreationDate($extLinkRow['CREATION_DATE']);
                 continue;
             }
             $targetElement = CIBlockElement::getList(array(), array('=NAME' => $nameOfElement, 'IBLOCK_ID' => $prevIblockId, 'SECTION_ID' => $prevSectionId), false, false, array('ID'))->fetch();
             if (!$targetElement || empty($targetElement['ID'])) {
                 $this->log(array('Could not migrate ext.link (find iblockElement)', $extLinkRow));
                 $this->storeConvertedExtLinkCreationDate($extLinkRow['CREATION_DATE']);
                 continue;
             }
             $targetElement['ID'] = (int) $targetElement['ID'];
             $result = $this->connection->query("SELECT ID FROM b_disk_object WHERE WEBDAV_ELEMENT_ID = {$targetElement['ID']}")->fetch();
             if (!$result || empty($result['ID'])) {
                 $this->log(array('Could not migrate ext.link (find b_disk_object)', $extLinkRow));
                 $this->storeConvertedExtLinkCreationDate($extLinkRow['CREATION_DATE']);
                 continue;
             }
             $extLinkData['OBJECT_ID'] = $result['ID'];
         } elseif (!empty($extLinkRow['ROOT_SECTION_ID']) && !empty($extLinkRow['URL'])) {
             $this->log(array('Migrate ext.link from user storage (may contains symbolic link)'));
             $success = true;
             $pathItems = explode('/', ltrim($extLinkRow['URL'], '/'));
             $nameOfElement = array_pop($pathItems);
             $prevSectionId = $extLinkRow['ROOT_SECTION_ID'];
             $prevIblockId = $extLinkRow['IBLOCK_ID'];
             foreach ($pathItems as $path) {
                 $pathFilter = array('=NAME' => $path, 'IBLOCK_ID' => $prevIblockId, 'SECTION_ID' => $prevSectionId);
                 $section = CIBlockSection::getList(array(), $pathFilter, false, array('ID', 'IBLOCK_ID', 'UF_LINK_IBLOCK_ID', 'UF_LINK_SECTION_ID'))->fetch();
                 if (!$section) {
                     $success = false;
                     break;
                 }
                 $prevSectionId = empty($section['UF_LINK_SECTION_ID']) ? $section['ID'] : $section['UF_LINK_SECTION_ID'];
                 $prevIblockId = empty($section['UF_LINK_IBLOCK_ID']) ? $section['IBLOCK_ID'] : $section['UF_LINK_IBLOCK_ID'];
             }
             unset($path);
             if (!$success) {
                 $this->log(array('Could not migrate ext.link (resolve symbolic path)', $extLinkRow));
                 $this->storeConvertedExtLinkCreationDate($extLinkRow['CREATION_DATE']);
                 continue;
             }
             $targetElement = CIBlockElement::getList(array(), array('=NAME' => $nameOfElement, 'IBLOCK_ID' => $prevIblockId, 'SECTION_ID' => $prevSectionId), false, false, array('ID'))->fetch();
             if (!$targetElement || empty($targetElement['ID'])) {
                 $this->log(array('Could not migrate ext.link (find iblockElement)', $extLinkRow));
                 $this->storeConvertedExtLinkCreationDate($extLinkRow['CREATION_DATE']);
                 continue;
             }
             $targetElement['ID'] = (int) $targetElement['ID'];
             $result = $this->connection->query("SELECT ID FROM b_disk_object WHERE WEBDAV_ELEMENT_ID = {$targetElement['ID']}")->fetch();
             if (!$result || empty($result['ID'])) {
                 $this->log(array('Could not migrate ext.link (find b_disk_object)', $extLinkRow));
                 $this->storeConvertedExtLinkCreationDate($extLinkRow['CREATION_DATE']);
                 continue;
             }
             $extLinkData['OBJECT_ID'] = $result['ID'];
         }
         $result = ExternalLinkTable::add($extLinkData);
         if (!$result->isSuccess()) {
             $this->log(array('Could not add new ext.link', $extLinkData, $result->getErrors()));
             $this->storeConvertedExtLinkCreationDate($extLinkRow['CREATION_DATE']);
             continue;
         }
         $this->log(array('Success attempt', $result->getId()));
         $this->storeConvertedExtLinkCreationDate($extLinkRow['CREATION_DATE']);
     }
     $this->setStepFinished(__METHOD__);
     $this->log(array('Finish migrate external links'));
     return array($successCount, $failedCount);
 }
Exemplo n.º 4
0
 /**
  * Deletes file and all connected data and entities (@see Sharing, @see Rights, etc).
  * @param int $deletedBy Id of user.
  * @return bool
  * @throws \Bitrix\Main\ArgumentNullException
  */
 public function delete($deletedBy)
 {
     $this->errorCollection->clear();
     $success = EditSessionTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     $success = ExternalLinkTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     foreach ($this->getSharingsAsReal() as $sharing) {
         $sharing->delete($deletedBy);
     }
     //with status unreplied, declined (not approved)
     $success = SharingTable::deleteByFilter(array('REAL_OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     foreach ($this->getAttachedObjects() as $attached) {
         $attached->delete();
     }
     unset($attached);
     BizProcDocument::deleteWorkflowsFile($this->id);
     SimpleRightTable::deleteBatch(array('OBJECT_ID' => $this->id));
     $success = RightTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     $success = VersionTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     DeletedLog::addFile($this, $deletedBy, $this->errorCollection);
     \CFile::delete($this->fileId);
     $deleteResult = FileTable::delete($this->id);
     if (!$deleteResult->isSuccess()) {
         return false;
     }
     Driver::getInstance()->getIndexManager()->dropIndex($this);
     if (!$this->isLink()) {
         //todo potential - very hard operation.
         foreach (File::getModelList(array('filter' => array('REAL_OBJECT_ID' => $this->id, '!=REAL_OBJECT_ID' => $this->id))) as $link) {
             $link->delete($deletedBy);
         }
         unset($link);
     }
     $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterDeleteFile", array($this->getId(), $deletedBy));
     $event->send();
     return true;
 }
Exemplo n.º 5
0
 protected function deleteProcess($deletedBy, $withDeletingSharing = true)
 {
     $this->errorCollection->clear();
     $success = EditSessionTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     $success = ExternalLinkTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if ($withDeletingSharing) {
         foreach ($this->getSharingsAsLink() as $sharing) {
             $sharing->delete($deletedBy, false);
         }
         //with status unreplied, declined (not approved)
         $success = SharingTable::deleteByFilter(array('REAL_OBJECT_ID' => $this->id));
     }
     if (!$success) {
         return false;
     }
     SimpleRightTable::deleteBatch(array('OBJECT_ID' => $this->id));
     $success = RightTable::deleteByFilter(array('OBJECT_ID' => $this->id));
     if (!$success) {
         return false;
     }
     DeletedLog::addFile($this, $deletedBy, $this->errorCollection);
     $resultDelete = FileTable::delete($this->id);
     if (!$resultDelete->isSuccess()) {
         return false;
     }
     $event = new Event(Driver::INTERNAL_MODULE_ID, "onAfterDeleteFile", array($this->getId(), $deletedBy));
     $event->send();
     return true;
 }