From 9a7e5d5bd37ed683920ea0384ebb2e6eb60802ce Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 21 Sep 2018 13:29:47 -0400 Subject: [PATCH] Add PagefilesManager->importFiles() and PagefilesManager->replaceFiles() methods --- wire/core/PagefilesManager.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/wire/core/PagefilesManager.php b/wire/core/PagefilesManager.php index 2ea0c416..d574371a 100644 --- a/wire/core/PagefilesManager.php +++ b/wire/core/PagefilesManager.php @@ -230,6 +230,40 @@ class PagefilesManager extends Wire { return $this->_copyFiles($this->path(), $toPath); } + /** + * Copy/import files from given path into the page’s files directory + * + * #pw-group-manipulation + * + * @param string $fromPath Path to copy/import files from. + * @param bool $move Move files into directory rather than copy? + * @return int Number of files/directories copied. + * @since 3.0.114 + * + */ + public function importFiles($fromPath, $move = false) { + return $this->_copyFiles($fromPath, $this->path(), $move); + } + + /** + * Replace all page’s files with those from given path + * + * #pw-group-manipulation + * + * @param string $fromPath + * @param bool $move Move files to destination rather than copy? (default=false) + * @return int Number of files/directories copied. + * @throws WireException if given a path that does not exist. + * @since 3.0.114 + * + * + */ + public function replaceFiles($fromPath, $move = false) { + if(!is_dir($fromPath)) throw new WireException("Path does not exist: $fromPath"); + $this->emptyPath(); + return $this->_copyFiles($fromPath, $this->path(), $move); + } + /** * Recursively move all files managed by this PagefilesManager into a new path. *