/** * Extract an archive out of an item and into the hierarchy in place. * * @param ItemDao $itemDao item representing the archive to extract * @param bool $deleteArchive whether to delete the archive item when finished extraction * @param UserDao $user user DAO * @param null|ProgressDao $progressDao progress DAO * @return FolderDao * @throws Zend_Exception */ public function extractInPlace($itemDao, $deleteArchive, $user, $progressDao = null) { $this->Item = MidasLoader::loadModel('Item'); $this->Folder = MidasLoader::loadModel('Folder'); $this->Folderpolicyuser = MidasLoader::loadModel('Folderpolicyuser'); $this->Folderpolicygroup = MidasLoader::loadModel('Folderpolicygroup'); $this->Progress = MidasLoader::loadModel('Progress'); $this->Setting = MidasLoader::loadModel('Setting'); $this->UploadComponent = MidasLoader::loadComponent('Upload'); $this->user = $user; $rev = $this->Item->getLastRevision($itemDao); if (!$rev) { throw new Zend_Exception('This item has no revisions'); } $bitstreams = $rev->getBitstreams(); if (count($bitstreams) !== 1) { throw new Zend_Exception('Head revision must have only one bitstream'); } if ($progressDao) { $this->Progress->updateProgress($progressDao, 0, 'Preparing to extract archive...'); } $bitstreamDao = $bitstreams[0]; $name = $bitstreamDao->getName(); $folders = $itemDao->getFolders(); $parentFolder = $folders[0]; // First extract the archive into a temp location on disk if ($this->_isFileExtension($name, '.zip')) { $extractedPath = $this->_extractZip($bitstreamDao, $progressDao); } else { throw new Zend_Exception('This file is not a supported archive type'); } // Next create the hierarchy from the temp location if ($progressDao) { $this->Progress->updateProgress($progressDao, 0, 'Adding items to Midas tree...'); } $this->_addToHierarchy($extractedPath, $parentFolder, $progressDao); // Clean up the dirs we made in the temp directory UtilityComponent::rrmdir($extractedPath); // Finally, delete existing archive item if user has specified to do so if ($deleteArchive) { if ($progressDao) { $progressDao->setMessage('Deleting old archive...'); $this->Progress->save($progressDao); } $this->Item->delete($itemDao); } return $parentFolder; }