/** * 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; }
/** * 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; } }
/** * 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; }
/** * 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; }
public function testMove() { $this->assertTrue(f::move($this->tmpFile, TEST_ROOT_TMP . DS . 'moved.txt')); }
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; }
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')); }
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')); }
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')); }
/** * 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; }
/** * 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>'); }