Пример #1
0
 /**
  * @param Skill $skill
  */
 protected function postDelete(Skill $skill)
 {
     // delete folder
     $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
     $dir = new Directory($module->getSkillPath($skill));
     $dir->delete();
 }
Пример #2
0
 /**
  * Writes contents to the file
  *
  * @param string $contents
  * @return $this
  */
 public function write($contents)
 {
     $dir = new Directory($this->getDirname());
     $dir->make();
     file_put_contents($this->pathname, $contents);
     return $this;
 }
Пример #3
0
 /**
  * @param Sport $sport
  * @param array $data
  */
 protected function postSave(Sport $sport, array $data)
 {
     // upload picture
     if (isset($data['meta']) && isset($data['meta']['filename']) && !empty($data['meta']['filename'])) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         // ensure directory
         $dir = new Directory($module->getSportPath($sport));
         if (!$dir->exists()) {
             $dir->make();
         }
         $destpath = $module->getSkillPreviewPath($sport);
         $dest = new File($destpath);
         if ($dest->exists()) {
             $dest->delete();
         }
         $file = new File($module->getUploadPath()->append($data['meta']['filename']));
         $imagine = new Imagine();
         $image = $imagine->open($file->toPath()->toString());
         $image->save($dest->toPath()->toString());
         $file->delete();
         $sport->setSkillPictureUrl($module->getSkillPreviewUrl($sport));
         $sport->save();
     }
     // delete picture
     if (isset($data['meta']) && isset($data['meta']['skill_picture_delete']) && $data['meta']['skill_picture_delete'] == 1) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         $path = $module->getSkillPreviewPath($sport);
         $file = new File($path);
         $file->delete();
         $sport->setSkillPictureUrl(null);
         $sport->save();
     }
 }
Пример #4
0
 /**
  * @expectedException phootwork\file\exception\FileException
  */
 public function testDeleteWithFailure()
 {
     $prj = new Directory($this->createProject());
     $root = new Directory($this->root->url());
     $root->setMode(0555);
     $prj->delete();
 }
Пример #5
0
 /**
  * @param Picture $picture
  * @param array $data
  */
 protected function postSave(Picture $picture, array $data)
 {
     if (isset($data['meta']) && isset($data['meta']['filename'])) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         $file = new File($module->getUploadPath()->append($data['meta']['filename']));
         $slugifier = new Slugify();
         $filename = sprintf('%s-%u.%s', $slugifier->slugify($picture->getAthlete()), $picture->getId(), $file->getExtension());
         $filepath = $module->getPicturesPath($picture->getSkill())->append($filename);
         $file->move($filepath);
         // create thumb folder
         $thumbspath = $module->getPicturesPath($picture->getSkill())->append('thumbs');
         $dir = new Directory($thumbspath);
         if (!$dir->exists()) {
             $dir->make();
         }
         // create thumb
         $imagine = new Imagine();
         $image = $imagine->open($filepath->toString());
         $max = max($image->getSize()->getWidth(), $image->getSize()->getHeight());
         $width = $image->getSize()->getWidth() / $max * self::THUMB_MAX_SIZE;
         $height = $image->getSize()->getHeight() / $max * self::THUMB_MAX_SIZE;
         $size = new Box($width, $height);
         $thumbpath = $thumbspath->append($filename);
         $image->thumbnail($size)->save($thumbpath->toString());
         // save to picture
         $picture->setUrl($module->getPicturesUrl($picture->getSkill()) . '/' . $filename);
         $picture->setThumbUrl($module->getPicturesUrl($picture->getSkill()) . '/thumbs/' . $filename);
         $picture->save();
     }
     // activity
     $user = $this->getServiceContainer()->getAuthManager()->getUser();
     $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_UPLOAD : Activity::VERB_EDIT, 'object' => $picture, 'target' => $picture->getSkill()));
 }
Пример #6
0
 public function testTypes()
 {
     $this->assertTrue(Directory::create('') instanceof Directory);
     $this->assertTrue(File::create('') instanceof File);
     $this->assertTrue(FileDescriptor::create('') instanceof FileDescriptor);
     $this->assertTrue(is_string(File::create('/path/to/dir')->getPathname()));
     $this->assertTrue(is_string(Directory::create(new Path('/path/to/dir'))->getPathname()));
     $this->assertTrue(is_string(FileDescriptor::create(new Text('/path/to/dir'))->getPathname()));
 }
Пример #7
0
 /**
  * Creates a symlink to the given destination
  * 
  * @param string|Path $destination
  */
 public function linkTo($destination)
 {
     $target = new FileDescriptor($destination);
     $targetDir = new Directory($target->getDirname());
     $targetDir->make();
     $ok = false;
     if ($target->isLink()) {
         if (!$target->getLinkTarget()->equals($this->pathname)) {
             $target->delete();
         } else {
             $ok = true;
         }
     }
     if (!$ok && @symlink($this->pathname, $target->getPathname()) !== true) {
         $report = error_get_last();
         if (is_array($report) && DIRECTORY_SEPARATOR === '\\' && strpos($report['message'], 'error code(1314)') !== false) {
             throw new FileException('Unable to create symlink due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?');
         }
         throw new FileException(sprintf('Failed to create symbolic link from %s to %s', $this->pathname, $targetDir));
     }
 }
Пример #8
0
 /**
  * @expectedException phootwork\file\exception\FileException
  */
 public function testDeleteWithFailure()
 {
     $dir = new Directory($this->root->url() . '/dir');
     $dir->make();
     $file = new File($this->root->url() . '/dir/composer.json');
     $file->touch();
     $this->assertTrue($file->exists());
     $dir->setMode(0555);
     $file->delete();
     $this->assertFalse($file->exists());
 }
Пример #9
0
 /**
  * Returns the path for managed files for this module
  *
  * @return Path
  */
 public function getFilesPath()
 {
     $repo = $this->getServiceContainer()->getResourceRepository();
     if (!$repo->contains($this->getFilesPuliPath())) {
         $dir = new Directory($repo->get('/files')->getFilesystemPath());
         $path = $dir->toPath()->append('managed/' . $this->model->getName());
         $dir = new Directory($path);
         $dir->make();
     }
     $dir = new Directory($repo->get($this->getFilesPuliPath())->getFilesystemPath());
     return $dir->toPath();
 }