move() 정적인 공개 메소드

Moves a file to a new location
static public move ( string $old, string $new ) : boolean
$old string The current path for the file
$new string The path to the new location
리턴 boolean
예제 #1
0
 /**
  * Renames the file and also its meta info txt
  *
  * @param string $filename
  */
 public function rename($name)
 {
     $filename = f::safeName($name) . '.' . $this->extension();
     $root = $this->dir() . DS . $filename;
     if ($root == $this->root()) {
         return $filename;
     }
     if (file_exists($root)) {
         throw new Exception('A file with that name already exists');
     }
     if (!f::move($this->root(), $root)) {
         throw new Exception('The file could not be renamed');
     }
     $meta = $this->textfile();
     if (file_exists($meta)) {
         f::move($meta, $this->page->textfile($filename));
     }
     cache::flush();
     return $filename;
 }
예제 #2
0
 /**
  * Moves the file to a new location
  *
  * @param string $to
  * @return boolean
  */
 public function move($to)
 {
     if (!f::move($this->root, $to)) {
         return false;
     } else {
         $this->root = $to;
         return true;
     }
 }
예제 #3
0
파일: file.php 프로젝트: smongey/ck
 /**
  * Renames the file and also its meta info txt
  *
  * @param string $filename
  */
 public function rename($name)
 {
     $filename = $this->createNewFilename($name);
     $root = $this->dir() . DS . $filename;
     if (empty($name)) {
         throw new Exception('The filename is missing');
     }
     if ($root == $this->root()) {
         return $filename;
     }
     if (file_exists($root)) {
         throw new Exception('A file with that name already exists');
     }
     if (!f::move($this->root(), $root)) {
         throw new Exception('The file could not be renamed');
     }
     $meta = $this->textfile();
     if (file_exists($meta)) {
         f::move($meta, $this->page->textfile($filename));
     }
     // reset the page cache
     $this->page->reset();
     cache::flush();
     return $filename;
 }
예제 #4
0
 /**
  * Renames the file and also its meta info txt
  *  
  * @param string $filename
  */
 public function rename($name)
 {
     $filename = f::safeName($name) . '.' . $this->extension();
     $root = $this->dir() . DS . $filename;
     if (empty($name)) {
         throw new Exception('The filename is missing');
     }
     if ($root == $this->root()) {
         return $filename;
     }
     if (file_exists($root)) {
         throw new Exception('A file with that name already exists');
     }
     if (!f::move($this->root(), $root)) {
         throw new Exception('The file could not be renamed');
     }
     foreach ($this->site->languages() as $lang) {
         // rename all meta files
         $meta = $this->textfile($lang->code());
         if (file_exists($meta)) {
             f::move($meta, $this->page->textfile($filename, $lang->code()));
         }
     }
     return $filename;
 }
예제 #5
0
 public function testMove()
 {
     $this->assertTrue(f::move($this->tmpFile, TEST_ROOT_TMP . DS . 'moved.txt'));
 }
예제 #6
0
파일: page.php 프로젝트: nsteiner/kdoc
 public function changeTemplate($newTemplate)
 {
     $oldTemplate = $this->intendedTemplate();
     if ($newTemplate == $oldTemplate) {
         return true;
     }
     if ($this->site()->multilang()) {
         foreach ($this->site()->languages() as $lang) {
             $old = $this->textfile(null, $lang->code());
             $new = $this->textfile($newTemplate, $lang->code());
             f::move($old, $new);
             $this->reset();
             $this->updateForNewTemplate($oldTemplate, $newTemplate, $lang->code());
         }
     } else {
         $old = $this->textfile();
         $new = $this->textfile($newTemplate);
         f::move($old, $new);
         $this->reset();
         $this->updateForNewTemplate($oldTemplate, $newTemplate);
     }
     return true;
 }
예제 #7
0
 static function editFile()
 {
     global $page;
     $filename = get('filename');
     $newname = str::urlify(get('newname'));
     $file = $page->files()->find($filename);
     if (!$file) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.notfound'));
     }
     $newfilename = $newname . '.' . $file->extension();
     if ($newfilename == $file->filename()) {
         return array('status' => 'success', 'msg' => l::get('nochanges'));
     }
     $newroot = dirname($file->root()) . '/' . $newfilename;
     if (file_exists($newroot)) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.exists'));
     }
     if (!f::move($file->root(), $newroot)) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.permissions'));
     }
     self::killCache();
     return array('status' => 'success', 'msg' => l::get('files.edit.success'));
 }
예제 #8
0
 static function editFile()
 {
     global $panel, $page;
     $filename = get('filename');
     $newname = str::urlify(get('newname'));
     $file = $page->files()->find($filename);
     if (!$file) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.notfound'));
     }
     if (str::length($newname) < 1) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.filename'));
     }
     $newfilename = $newname . '.' . $file->extension();
     if ($newfilename != $file->filename()) {
         $newroot = dirname($file->root()) . '/' . $newfilename;
         if (file_exists($newroot)) {
             return array('status' => 'error', 'msg' => l::get('files.edit.errors.exists'));
         }
         if (!f::move($file->root(), $newroot)) {
             return array('status' => 'error', 'msg' => l::get('files.edit.errors.permissions'));
         }
         // delete the old meta file
         if (c::get('lang.support')) {
             // make sure to remove the meta file without language extension
             $invalidfile = dirname($file->root()) . '/' . $file->filename() . '.' . c::get('content.file.extension', 'txt');
             f::remove($invalidfile);
             // remove the translated meta file
             $oldmeta = dirname($file->root()) . '/' . $file->filename() . '.' . c::get('lang.current') . '.' . c::get('content.file.extension', 'txt');
         } else {
             $oldmeta = dirname($file->root()) . '/' . $file->filename() . '.' . c::get('content.file.extension', 'txt');
         }
         f::remove($oldmeta);
     }
     if (c::get('lang.support')) {
         // delete the untranslated file
         $delete = dirname($file->root()) . '/' . $newfilename . '.' . c::get('content.file.extension', 'txt');
         f::remove($delete);
         // set the translated file
         $destination = dirname($file->root()) . '/' . $newfilename . '.' . c::get('lang.current') . '.' . c::get('content.file.extension', 'txt');
     } else {
         $destination = dirname($file->root()) . '/' . $newfilename . '.' . c::get('content.file.extension', 'txt');
     }
     $updateInfo = self::updateFileinfo($file, $destination);
     if (error($updateInfo)) {
         return $updateInfo;
     }
     self::killCache();
     return array('status' => 'success', 'msg' => l::get('files.edit.success'));
 }
예제 #9
0
파일: data.php 프로젝트: 04x10/04x10.com
 static function editFile()
 {
     global $panel, $page;
     $filename = get('filename');
     $newname = str::urlify(get('newname'));
     $file = $page->files()->find($filename);
     if (!$file) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.notfound'));
     }
     if (str::length($newname) < 1) {
         return array('status' => 'error', 'msg' => l::get('files.edit.errors.filename'));
     }
     $newfilename = $newname . '.' . $file->extension();
     if ($newfilename != $file->filename()) {
         $newroot = dirname($file->root()) . '/' . $newfilename;
         if (file_exists($newroot)) {
             return array('status' => 'error', 'msg' => l::get('files.edit.errors.exists'));
         }
         if (!f::move($file->root(), $newroot)) {
             return array('status' => 'error', 'msg' => l::get('files.edit.errors.permissions'));
         }
         // delete the old meta file
         $oldmeta = dirname($file->root()) . '/' . $file->filename() . '.txt';
         f::remove($oldmeta);
     }
     $destination = dirname($file->root()) . '/' . $newfilename . '.txt';
     $updateInfo = self::updateFileinfo($file, $destination);
     if (error($updateInfo)) {
         return $updateInfo;
     }
     self::killCache();
     return array('status' => 'success', 'msg' => l::get('files.edit.success'));
 }
예제 #10
0
 /**
  * Renames the file and also its meta info txt
  *  
  * @param string $filename
  * @param boolean $safeName
  */
 public function rename($name, $safeName = true)
 {
     $filename = $this->createNewFilename($name, $safeName);
     $root = $this->dir() . DS . $filename;
     if ($root == $this->root()) {
         return $filename;
     }
     if (file_exists($root)) {
         throw new Exception('A file with that name already exists');
     }
     if (!f::move($this->root(), $root)) {
         throw new Exception('The file could not be renamed');
     }
     foreach ($this->site->languages() as $lang) {
         // rename all meta files
         $meta = $this->textfile($lang->code());
         if (file_exists($meta)) {
             f::move($meta, $this->page->textfile($filename, $lang->code()));
         }
     }
     // reset the page cache
     $this->page->reset();
     // reset the basics
     $this->root = $root;
     $this->filename = $filename;
     $this->name = $name;
     $this->cache = array();
     cache::flush();
     return $filename;
 }
예제 #11
0
파일: Plugin.php 프로젝트: getkirby/cli
 /**
  * Move the source to the final destination
  */
 protected function move()
 {
     $exists = $this->pluginExists();
     $error = $exists ? 'The plugin could not be updated' : 'The plugin could not be installed';
     $success = $exists ? 'The plugin has been updated to version:' : 'The plugin has been installed at version:';
     if ($exists) {
         $this->output->writeln('<info>Updating plugin...</info>');
     } else {
         $this->output->writeln('<info>Installing plugin...</info>');
     }
     $this->output->writeln('<info></info>');
     $this->prepare();
     $src = $this->source();
     $dest = $this->destination();
     // overwriting means having to clean the plugin first
     if (is_dir($dest)) {
         if (!dir::remove($dest)) {
             throw new RuntimeException('The old plugin could not be removed before the update');
         }
     }
     if (is_file($src)) {
         if (!f::move($src, $dest)) {
             throw new RuntimeException($error);
         }
     } else {
         if (is_dir($src)) {
             if (!dir::move($src, $dest)) {
                 throw new RuntimeException($error);
             }
         } else {
             throw new RuntimeException('Invalid source');
         }
     }
     $this->output->writeln('<comment>' . $success . ' "' . $this->version() . '"</comment>');
 }