Пример #1
0
 /**
  * Put a file
  *
  * @param   string filename
  * @param   mixed data
  * @param   string resourcetype, default NULL
  * @return  bool new
  * @throws  org.webdav.OperationNotAllowedException
  * @throws  org.webdav.OperationFailedException
  */
 public function put($filename, $data, $resourcetype = NULL)
 {
     $uri = $this->base . $filename;
     if (is_dir($uri)) {
         throw new OperationNotAllowedException($uri . ' cannot be written (not a file)');
     }
     // Open file and write contents
     $f = new File($uri);
     // Check if VersionControl is activated
     if (($prop = $this->propStorage->getProperty($filename, 'D:version')) !== NULL) {
         $container = $prop->value;
         $newVersion = WebdavVersionUtil::getNextVersion($container->getLatestVersion(), $f);
         $container->addVersion($newVersion);
         // Re-Add modified container to property
         $prop->value = $container;
         // Save property
         $this->propStorage->setProperty($filename, $prop);
         // Now, copy the "old" file to versions directory
         $this->backup($filename, '../versions/' . dirname($filename) . '/' . $newVersion->getVersionName());
     }
     try {
         $new = !$f->exists();
         $f->open(FILE_MODE_WRITE);
         $f->write($data);
         $f->close();
     } catch (IOException $e) {
         throw new OperationFailedException($filename . ' cannot be written ' . $e->toString());
     }
     // Set the resourcetype on first put
     if (($prop = $this->propStorage->getProperty($filename, 'D:resourcetype')) == NULL) {
         // Set ResourceType
         with($p = new WebdavProperty('resourcetype', $resourcetype));
         $p->setNameSpaceName('DAV:');
         $p->setNameSpacePrefix('D:');
         $this->propStorage->setProperty($filename, $p);
     }
     return $new;
 }
Пример #2
0
 /**
  * Start Version-Control of file
  *
  * @param   string filename
  * @return  bool
  * @throws  lang.ElementNotFoundException
  */
 public function VersionControl($path, $version)
 {
     $props = array();
     // Set versions as properties
     with($p = new WebdavProperty('version', new WebdavVersionsContainer($version)));
     $p->setNameSpaceName('DAV:');
     $p->setNameSpacePrefix('D:');
     $props[$p->getNameSpacePrefix() . $p->getName()] = $p;
     // Set checked-in property
     with($p = new WebdavProperty('checked-in', '1.0'));
     $p->setNameSpaceName('DAV:');
     $p->setNameSpacePrefix('D:');
     $props[$p->getNameSpacePrefix() . $p->getName()] = $p;
     $this->propStorage->setProperties($path, $props);
     // Copy file to versions collection
     $this->backup($path, $version->getHref());
     return TRUE;
 }