Exemple #1
0
 public function duplicate()
 {
     $db = Loader::db();
     $em = \ORM::entityManager('core');
     $versions = $this->versions;
     // duplicate the core file object
     $nf = clone $this;
     $dh = Loader::helper('date');
     $date = $dh->getOverridableNow();
     $nf->fDateAdded = new Carbon($date);
     $em->persist($nf);
     $em->flush();
     // clear out the versions
     $nf->versions = new ArrayCollection();
     $fi = Core::make('helper/file');
     $cf = Core::make('helper/concrete/file');
     $importer = new Importer();
     $filesystem = $this->getFileStorageLocationObject()->getFileSystemObject();
     foreach ($versions as $version) {
         if ($version->isApproved()) {
             $cloneVersion = clone $version;
             $cloneVersion->setFile($nf);
             do {
                 $prefix = $importer->generatePrefix();
                 $path = $cf->prefix($prefix, $version->getFilename());
             } while ($filesystem->has($path));
             $filesystem->write($path, $version->getFileResource()->read(), array('visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => Core::make('helper/mime')->mimeFromExtension($fi->getExtension($version->getFilename()))));
             $cloneVersion->updateFile($version->getFilename(), $prefix);
             $nf->versions->add($cloneVersion);
         }
     }
     $em->persist($nf);
     $em->flush();
     $r = $db->Execute('select fvID, akID, avID from FileAttributeValues where fID = ?', array($this->getFileID()));
     while ($row = $r->fetchRow()) {
         $db->Execute("insert into FileAttributeValues (fID, fvID, akID, avID) values (?, ?, ?, ?)", array($nf->getFileID(), $row['fvID'], $row['akID'], $row['avID']));
     }
     $v = array($this->fID);
     $q = "select fID, paID, pkID from FilePermissionAssignments where fID = ?";
     $r = $db->query($q, $v);
     while ($row = $r->fetchRow()) {
         $v = array($nf->getFileID(), $row['paID'], $row['pkID']);
         $q = "insert into FilePermissionAssignments (fID, paID, pkID) values (?, ?, ?)";
         $db->query($q, $v);
     }
     foreach ($nf->getVersionList() as $v) {
         $v->refreshAttributes();
     }
     $fe = new \Concrete\Core\File\Event\DuplicateFile($this);
     $fe->setNewFileObject($nf);
     Events::dispatch('on_file_duplicate', $fe);
     return $nf;
 }
Exemple #2
0
 public function duplicate()
 {
     $db = Loader::db();
     $em = \ORM::entityManager('core');
     $versions = $this->versions;
     // duplicate the core file object
     $nf = clone $this;
     $dh = Loader::helper('date');
     $date = $dh->getOverridableNow();
     $nf->fDateAdded = new Carbon($date);
     $em->persist($nf);
     $em->flush();
     // clear out the versions
     $nf->versions = new ArrayCollection();
     foreach ($versions as $version) {
         if ($version->isApproved()) {
             $cloneVersion = clone $version;
             $cloneVersion->setFile($nf);
             $cloneVersion->duplicateUnderlyingFile();
             $nf->versions->add($cloneVersion);
         }
     }
     $em->persist($nf);
     $em->flush();
     $r = $db->Execute('select fvID, akID, avID from FileAttributeValues where fID = ?', array($this->getFileID()));
     while ($row = $r->fetchRow()) {
         $db->Execute("insert into FileAttributeValues (fID, fvID, akID, avID) values (?, ?, ?, ?)", array($nf->getFileID(), $row['fvID'], $row['akID'], $row['avID']));
     }
     $v = array($this->fID);
     $q = "select fID, paID, pkID from FilePermissionAssignments where fID = ?";
     $r = $db->query($q, $v);
     while ($row = $r->fetchRow()) {
         $v = array($nf->getFileID(), $row['paID'], $row['pkID']);
         $q = "insert into FilePermissionAssignments (fID, paID, pkID) values (?, ?, ?)";
         $db->query($q, $v);
     }
     foreach ($nf->getVersionList() as $v) {
         $v->refreshAttributes();
     }
     $fe = new \Concrete\Core\File\Event\DuplicateFile($this);
     $fe->setNewFileObject($nf);
     Events::dispatch('on_file_duplicate', $fe);
     return $nf;
 }