/** * Rename $oldPath to $newPath * * @param string $oldPath Old filename/directory * @param string $newPath New filename/directory * @return bool True if rename was successful */ public function rename($oldPath, $newPath) { if (is_dir($oldPath)) { $Folder = new Folder($oldPath); return $Folder->move(array('from' => $oldPath, 'to' => $newPath)); } else { return rename($oldPath, $newPath); } }
/** * 保存 */ public function testSaveOnRename() { $path = WWW_ROOT . 'theme' . DS; $data = array('Theme' => array('old_name' => 'nada-icons', 'name' => 'new-nada-icons')); $this->Theme->save($data); $this->assertFileExists($path . 'new-nada-icons', 'ファイル名を変更できません'); $Folder = new Folder($path . 'new-nada-icons'); $Folder->move(['to' => $path . 'nada-icons']); }
function rollback($movers) { foreach ($movers as $m) { $path = ROOT . DS . $m; $to = $path . '.off'; if (is_dir($to)) { if (is_dir($path)) { $fr = new Folder($path); $fr->delete(); } $f = new Folder($to); $f->move($path); } else { if (file_exists($to)) { if (file_exists($path)) { unlink($path); } rename($to, $path); } } } }
/** * Move files and folders to their new homes * * Moves folders containing files which cannot necessarily be autodetected (libs and templates) * and then looks for all php files except vendors, and moves them to where Cake 2.0 expects * to find them. * * @return void */ public function locations() { $cwd = getcwd(); if (is_dir('plugins')) { $Folder = new Folder('plugins'); list($plugins) = $Folder->read(); foreach ($plugins as $plugin) { chdir($cwd . DS . 'plugins' . DS . $plugin); $this->locations(); } $this->_files = array(); chdir($cwd); } $moves = array('libs' => 'Lib', 'vendors' . DS . 'shells' . DS . 'templates' => 'Console' . DS . 'Templates'); foreach ($moves as $old => $new) { if (is_dir($old)) { $this->out("Moving {$old} to {$new}"); if (!$this->params['dry-run']) { $Folder = new Folder($old); $Folder->move($new); } if ($this->params['git']) { exec('git mv -f ' . escapeshellarg($old) . ' ' . escapeshellarg($new)); } } } $sourceDirs = array('.' => array('recursive' => false), 'Console', 'Controller', 'controllers', 'Lib' => array('checkFolder' => false), 'Model', 'models', 'tests', 'View', 'views', 'vendors/shells'); $defaultOptions = array('recursive' => true, 'checkFolder' => true); foreach ($sourceDirs as $dir => $options) { if (is_numeric($dir)) { $dir = $options; $options = array(); } $options = array_merge($defaultOptions, $options); $this->_movePhpFiles($dir, $options); } }
function update($plugin, $url = null) { App::import('Folder'); $this->formattedOut(String::insert(__d('plugin', "Atualizando [fg=green]:plugin[/fg]...", true), array('plugin' => $plugin)), false); if (empty($url)) { $url = $this->_url($plugin); } if (empty($url)) { $this->formattedOut(__d('plugin', "[fg=black][bg=red] ERRO [/bg][/fg]", true)); $this->formattedOut(__d('plugin', " -> O plugin nao existe ou nao possui uma url para atualizacao.", true)); $this->_stop(); } $this->out("\n", false); $pluginFolder = new Folder(); $pluginFolder->move(array('from' => $this->params['working'] . DS . 'plugins/' . $plugin, 'to' => $this->params['working'] . DS . 'plugins/' . $plugin . '-old')); $status = $this->Installer->install($url, $plugin); if ($status) { $pluginFolder->delete($this->params['working'] . DS . 'plugins/' . $plugin . '-old'); } else { $this->formattedOut(__d('plugin', "[fg=black][bg=red] ERRO [/bg][/fg]", true)); $this->formattedOut(__d('plugin', " -> Nao foi possivel atualizar o plugin.", true)); $pluginFolder->move(array('from' => $this->params['working'] . DS . 'plugins/' . $plugin . '-old', 'to' => $this->params['working'] . DS . 'plugins/' . $plugin)); } }
function update() { if (!PRODUCTION) { // Don't want to ever run this in development die('good'); } App::import('Vendor', 'bradleyboy/updater'); $old_mask = umask(0); // Move these to off position in case we need to rollback $movers = array('app', 'm', 'cron.php', 'images.php', 'index.php', 'p.php', 'popup.php'); foreach ($movers as $m) { $path = ROOT . DS . $m; $to = $path . '.off'; if (is_dir($path)) { $f = new Folder($path); $f->move($to); if (is_dir($path)) { umask($old_mask); rollback($movers); die('permfail'); } } else { if (file_exists($path)) { rename($path, $to); if (file_exists($path)) { umask($old_mask); rollback($movers); die('permfail'); } } } } $version = trim($this->Pigeon->version(true)); if ((strpos($version, 'b') !== false || strpos($version, 'a') !== false) && BETA_TEST) { $core = 'http://www.sspdirector.com/zips/upgrade_beta.zip'; } else { $core = 'http://www.sspdirector.com/zips/upgrade.zip'; } $zip_helper = 'http://www.sspdirector.com/zips/pclzip.lib.txt'; $local_core = ROOT . DS . 'core.zip'; $local_helper = ROOT . DS . 'pclzip.lib.php'; if (download_file($core, $local_core) && download_file($zip_helper, $local_helper)) { require $local_helper; $archive = new PclZip('core.zip'); $archive->extract(PCLZIP_CB_POST_EXTRACT, 'extract_callback'); } else { umask($old_mask); rollback($movers); die('permfail'); } foreach ($movers as $m) { $path = ROOT . DS . $m; $to = $path . '.off'; if (is_dir($to)) { $f = new Folder($path); $f->delete($to); } else { if (file_exists($to)) { unlink($to); } } } unlink($local_core); unlink($local_helper); umask($old_mask); die('good'); }
/** * Move file with 2 step process to avoid collisions on case insensitive systems * * @return void */ protected function _move($from, $to, $folder = true) { $tmp = '_tmp'; if ($this->params['git']) { exec('git mv -f ' . escapeshellarg($from) . ' ' . escapeshellarg($from . $tmp)); exec('git mv -f ' . escapeshellarg($from . $tmp) . ' ' . escapeshellarg($to)); } elseif ($this->params['tgit']) { exec('tgit mv -f ' . escapeshellarg($from) . ' ' . escapeshellarg($from . $tmp)); exec('tgit mv -f ' . escapeshellarg($from . $tmp) . ' ' . escapeshellarg($to)); } elseif ($this->params['svn']) { exec('"' . $this->params['svn'] . '" move --force ' . escapeshellarg($from) . ' ' . escapeshellarg($from . $tmp)); exec('"' . $this->params['svn'] . '" move --force ' . escapeshellarg($from . $tmp) . ' ' . escapeshellarg($to)); } elseif ($folder) { $Folder = new Folder($from); $Folder->move($to . $tmp); $Folder = new Folder($to . $tmp); $Folder->move($to); } else { rename($from, $to); } }
/** * testMove method * * Verify that directories and files are moved recursively * even if the destination directory already exists. * Subdirectories existing in both destination and source directory * are skipped and not merged or overwritten. * * @return void */ public function testMove() { $path = TMP . 'folder_test'; $folder1 = $path . DS . 'folder1'; $folder2 = $folder1 . DS . 'folder2'; $folder3 = $path . DS . 'folder3'; $file1 = $folder1 . DS . 'file1.php'; $file2 = $folder2 . DS . 'file2.php'; new Folder($path, true); new Folder($folder1, true); new Folder($folder2, true); new Folder($folder3, true); touch($file1); touch($file2); $Folder = new Folder($folder1); $result = $Folder->move($folder3); $this->assertTrue($result); $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); $this->assertTrue(is_dir($folder3 . DS . 'folder2')); $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php')); $this->assertFalse(file_exists($file1)); $this->assertFalse(file_exists($folder2)); $this->assertFalse(file_exists($file2)); $Folder = new Folder($folder3); $Folder->delete(); new Folder($folder1, true); new Folder($folder2, true); touch($file1); touch($file2); $Folder = new Folder($folder1); $result = $Folder->move($folder3); $this->assertTrue($result); $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); $this->assertTrue(is_dir($folder3 . DS . 'folder2')); $this->assertTrue(file_exists($folder3 . DS . 'folder2' . DS . 'file2.php')); $this->assertFalse(file_exists($file1)); $this->assertFalse(file_exists($folder2)); $this->assertFalse(file_exists($file2)); $Folder = new Folder($folder3); $Folder->delete(); new Folder($folder1, true); new Folder($folder2, true); new Folder($folder3, true); new Folder($folder3 . DS . 'folder2', true); touch($file1); touch($file2); file_put_contents($folder3 . DS . 'folder2' . DS . 'file2.php', 'untouched'); $Folder = new Folder($folder1); $result = $Folder->move($folder3); $this->assertTrue($result); $this->assertTrue(file_exists($folder3 . DS . 'file1.php')); $this->assertEquals(file_get_contents($folder3 . DS . 'folder2' . DS . 'file2.php'), 'untouched'); $this->assertFalse(file_exists($file1)); $this->assertFalse(file_exists($folder2)); $this->assertFalse(file_exists($file2)); $Folder = new Folder($path); $Folder->delete(); }
/** * フォルダ編集 * * @return void * @access public */ public function admin_edit_folder() { $args = $this->_parseArgs(func_get_args()); extract($args); if (!isset($this->_tempalteTypes[$type])) { $this->notFound(); } if (!$this->request->data) { $this->request->data['ThemeFolder']['name'] = basename($path); $this->request->data['ThemeFolder']['parent'] = dirname($fullpath); $this->request->data['ThemeFolder']['pastname'] = basename($path); } else { $newPath = dirname($fullpath) . DS . $this->request->data['ThemeFolder']['name'] . DS; $folder = new Folder(); $this->ThemeFolder->set($this->request->data); if ($this->ThemeFolder->validates()) { if ($fullpath != $newPath) { if ($folder->move(array('from' => $fullpath, 'to' => $newPath, 'chmod' => 0777, 'skip' => array('_notes')))) { $this->setMessage('フォルダ名を ' . $this->request->data['ThemeFolder']['name'] . ' に変更しました。'); $this->redirect(array_merge(array('action' => 'index', $theme, $type), explode('/', dirname($path)))); } else { $this->setMessage('フォルダ名の変更に失敗しました。', true); } } else { $this->setMessage('フォルダ名に変更はありませんでした。', true); $this->redirect(array_merge(array('action' => 'index', $theme, $type), explode('/', dirname($path)))); } } else { $this->setMessage('フォルダ名の変更に失敗しました。', true); } } $pageTitle = $theme; $this->pageTitle = '[' . $pageTitle . '] フォルダ表示: ' . basename($path); $this->crumbs[] = array('name' => $this->_tempalteTypes[$type], 'url' => array('controller' => 'theme_files', 'action' => 'index', $theme, $type)); $this->subMenuElements = array('theme_files'); $this->set('currentPath', str_replace(ROOT, '', dirname($fullpath)) . '/'); $this->set('theme', $theme); $this->set('plugin', $plugin); $this->set('type', $type); $this->set('path', $path); $this->help = 'theme_files_form_folder'; $this->render('form_folder'); }
// der entsprechende Ordner konnte nicht angelegt werden $gMessage->setForwardUrl($g_root_path . '/adm_program/modules/photos/photos.php'); $gMessage->show($gL10n->get($error['text'], $error['path'], '<a href="mailto:' . $gPreferences['email_administrator'] . '">', '</a>')); } if (strlen($error['text']) === 0) { // Benachrichtigungs-Email für neue Einträge $notification = new Email(); $message = $gL10n->get('PHO_EMAIL_NOTIFICATION_MESSAGE', $gCurrentOrganization->getValue('org_longname'), $_POST['pho_name'], $gCurrentUser->getValue('FIRST_NAME') . ' ' . $gCurrentUser->getValue('LAST_NAME'), date($gPreferences['system_date'], time())); $notification->adminNotfication($gL10n->get('PHO_EMAIL_NOTIFICATION_TITLE'), $message, $gCurrentUser->getValue('FIRST_NAME') . ' ' . $gCurrentUser->getValue('LAST_NAME'), $gCurrentUser->getValue('EMAIL')); } $getPhotoId = $photo_album->getValue('pho_id'); } elseif ($getMode === 'change' && $ordner != SERVER_PATH . '/adm_my_files/photos/' . $_POST['pho_begin'] . '_' . $getPhotoId) { $newFolder = SERVER_PATH . '/adm_my_files/photos/' . $_POST['pho_begin'] . '_' . $photo_album->getValue('pho_id'); // das komplette Album in den neuen Ordner kopieren $albumFolder = new Folder($ordner); $b_return = $albumFolder->move($newFolder); // Verschieben war nicht erfolgreich, Schreibrechte vorhanden ? if ($b_return == false) { $gMessage->setForwardUrl($g_root_path . '/adm_program/modules/photos/photos.php'); $gMessage->show($gL10n->get('SYS_FOLDER_WRITE_ACCESS', $newFolder, '<a href="mailto:' . $gPreferences['email_administrator'] . '">', '</a>')); } } //if /********************Aenderung der Datenbankeinträge***********************************/ if ($getMode === 'change') { // geaenderte Daten in der Datenbank akutalisieren $photo_album->save(); } unset($_SESSION['photo_album_request']); $gNavigation->deleteLastUrl(); header('Location: ' . $gNavigation->getUrl());
/** * Extract a theme from a zip file * * @param string $path Path to extension zip file * @param string $theme Optional theme name * @return boolean * @throws CakeException */ public function extractTheme($path = null, $theme = null) { if (!file_exists($path)) { throw new CakeException(__('Invalid theme file path')); } if (empty($theme)) { $theme = $this->getThemeName($path); } $themeHome = App::path('View'); $themeHome = reset($themeHome) . 'Themed' . DS; $themePath = $themeHome . $theme . DS; if (is_dir($themePath)) { throw new CakeException(__('Theme already exists')); } $Zip = new ZipArchive(); if ($Zip->open($path) === true) { new Folder($themePath, true); $Zip->extractTo($themePath); if (!empty($this->_rootPath[$path])) { $old = $themePath . $this->_rootPath[$path]; $new = $themePath; $Folder = new Folder($old); $Folder->move($new); } $Zip->close(); return true; } else { throw new CakeException(__('Failed to extract theme')); } return false; }
<?php if (!defined('MIGRATE')) { exit; } $oldies = $this->_query("SELECT id, path FROM {$atbl} WHERE path NOT LIKE 'album-%' AND path IS NOT NULL LIMIT 1"); if ($this->_rows($oldies) == 1) { $row = $this->_array($oldies); $old = ALBUMS . DS . $row['path']; $path = 'album-' . $row['id']; $new = ALBUMS . DS . $path; if (is_dir($old)) { $f = new Folder($old); $f->chmod($old, 0777); if ($f->move($new)) { $this->_query("UPDATE {$atbl} SET path = '{$path}-old-{$row['path']}' WHERE id = {$row['id']}"); } } else { $this->_query("UPDATE {$atbl} SET path = '{$path}-old-{$row['path']}' WHERE id = {$row['id']}"); } die('again'); }
/** * testMoveWithSkip method * * Verify that directories and files are moved recursively * even if the destination directory already exists. * Subdirectories existing in both destination and source directory * are skipped and not merged or overwritten. * * @return void */ public function testMoveWithSkip() { extract($this->_setupFilesystem()); $Folder = new Folder($folderOne); $result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP)); $this->assertTrue($result); $this->assertTrue(file_exists($folderTwo . DS . 'file1.php')); $this->assertTrue(is_dir($folderTwo . DS . 'folderB')); $this->assertTrue(file_exists($folderTwoB . DS . 'fileB.php')); $this->assertFalse(file_exists($fileOne)); $this->assertFalse(file_exists($folderOneA)); $this->assertFalse(file_exists($fileOneA)); $Folder = new Folder($folderTwo); $Folder->delete(); new Folder($folderOne, true); new Folder($folderOneA, true); new Folder($folderTwo, true); touch($fileOne); touch($fileOneA); $Folder = new Folder($folderOne); $result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP)); $this->assertTrue($result); $this->assertTrue(file_exists($folderTwo . DS . 'file1.php')); $this->assertTrue(is_dir($folderTwo . DS . 'folderA')); $this->assertTrue(file_exists($folderTwo . DS . 'folderA' . DS . 'fileA.php')); $this->assertFalse(file_exists($fileOne)); $this->assertFalse(file_exists($folderOneA)); $this->assertFalse(file_exists($fileOneA)); $Folder = new Folder($folderTwo); $Folder->delete(); new Folder($folderOne, true); new Folder($folderOneA, true); new Folder($folderTwo, true); new Folder($folderTwoB, true); touch($fileOne); touch($fileOneA); file_put_contents($folderTwoB . DS . 'fileB.php', 'untouched'); $Folder = new Folder($folderOne); $result = $Folder->move(array('to' => $folderTwo, 'scheme' => Folder::SKIP)); $this->assertTrue($result); $this->assertTrue(file_exists($folderTwo . DS . 'file1.php')); $this->assertEquals('untouched', file_get_contents($folderTwoB . DS . 'fileB.php')); $this->assertFalse(file_exists($fileOne)); $this->assertFalse(file_exists($folderOneA)); $this->assertFalse(file_exists($fileOneA)); $Folder = new Folder($path); $Folder->delete(); }
/** * フォルダ編集 * * @return void * @access public */ function admin_edit_folder() { $args = $this->_parseArgs(func_get_args()); extract($args); if (!isset($this->_tempalteTypes[$type])) { $this->notFound(); } if (!$this->data) { $this->data['ThemeFolder']['name'] = basename($path); $this->data['ThemeFolder']['parent'] = dirname($fullpath); $this->data['ThemeFolder']['pastname'] = basename($path); } else { $newPath = dirname($fullpath) . DS . $this->data['ThemeFolder']['name'] . DS; $folder = new Folder(); $this->ThemeFolder->set($this->data); if ($this->ThemeFolder->validates()) { if ($fullpath != $newPath) { if ($folder->move(array('from' => $fullpath, 'to' => $newPath, 'chmod' => 0777, 'skip' => array('_notes')))) { $this->Session->setFlash('フォルダ名を ' . $this->data['ThemeFolder']['name'] . ' に変更しました。'); $this->redirect(array('action' => 'index', $theme, $type, dirname($path))); } else { $this->Session->setFlash('フォルダ名の変更に失敗しました。'); } } else { $this->Session->setFlash('フォルダ名に変更はありませんでした。'); $this->redirect(array('action' => 'index', $theme, $type, dirname($path))); } } else { $this->Session->setFlash('フォルダ名の変更に失敗しました。'); } } $pageTitle = Inflector::camelize($theme); $this->pageTitle = '[' . $pageTitle . '] フォルダ表示: ' . basename($path); $this->navis[$this->_tempalteTypes[$type]] = '/admin/theme_files/index/' . $theme . '/' . $type; $this->subMenuElements = array('theme_files'); $this->set('currentPath', str_replace(ROOT, '', dirname($fullpath)) . '/'); $this->set('theme', $theme); $this->set('plugin', $plugin); $this->set('type', $type); $this->set('path', $path); $this->render('form_folder'); }
/** * プラグインをアップロードしてインストールする * * @return void */ public function admin_add() { $this->pageTitle = 'プラグインアップロード'; $this->subMenuElements = array('plugins'); //データなし if (empty($this->request->data)) { return; } //アップロード失敗 if (empty($this->request->data['Plugin']['file']['tmp_name'])) { $this->setMessage('ファイルのアップロードに失敗しました。', true); return; } $zippedName = $this->request->data['Plugin']['file']['name']; move_uploaded_file($this->request->data['Plugin']['file']['tmp_name'], TMP . $zippedName); $format = 'unzip -o ' . TMP . '%s' . ' -d ' . APP . 'Plugin' . DS; $command = sprintf($format, escapeshellarg($zippedName)); exec($command, $return); //ZIPファイル展開失敗 if (empty($return[2])) { $msg = 'アップロードしたZIPファイルの展開に失敗しました。'; exec('unzip 2>&1', $errs); $msg .= '<br />' . implode('<br />', $errs); $this->setMessage($msg, true); $this->redirect(array('action' => 'add')); return; } // 解凍したプラグインフォルダがキャメルケースでない場合にキャメルケースに変換 $plugin = preg_replace('/^\\s*?(creating|inflating):\\s*' . preg_quote(APP . 'Plugin' . DS, '/') . '/', '', $return[2]); $plugin = explode(DS, $plugin); $plugin = $plugin[0]; $srcPluginPath = APP . 'Plugin' . DS . $plugin; $Folder = new Folder(); $Folder->chmod($srcPluginPath, 0777); $tgtPluginPath = APP . 'Plugin' . DS . Inflector::camelize($plugin); if ($srcPluginPath != $tgtPluginPath) { $Folder->move(array('to' => $tgtPluginPath, 'from' => $srcPluginPath, 'mode' => 0777)); } unlink(TMP . $zippedName); // プラグインをインストール if ($this->BcManager->installPlugin($plugin)) { clearAllCache(); $this->setMessage('新規プラグイン「' . $plugin . '」を baserCMS に登録しました。', false, true); $this->Plugin->addFavoriteAdminLink($plugin, $this->BcAuth->user()); $this->redirect(array('action' => 'index')); } else { $this->setMessage('プラグインに問題がある為インストールを完了できません。プラグインの開発者に確認してください。', true); } }
/** * プラグインをアップロードしてインストールする * * @return void */ public function admin_add() { $this->pageTitle = 'プラグインアップロード'; $this->subMenuElements = array('plugins'); //データなし if (empty($this->request->data)) { return; } //アップロード失敗 if (empty($this->request->data['Plugin']['file']['tmp_name'])) { $this->setMessage('ファイルのアップロードに失敗しました。', true); return; } $zippedName = $this->request->data['Plugin']['file']['name']; move_uploaded_file($this->request->data['Plugin']['file']['tmp_name'], TMP . $zippedName); App::uses('BcZip', 'Lib'); $BcZip = new BcZip(); if (!$BcZip->extract(TMP . $zippedName, APP . 'Plugin' . DS)) { $msg = 'アップロードしたZIPファイルの展開に失敗しました。'; $msg .= '<br />' . $BcZip->error; $this->setMessage($msg, true); $this->redirect(array('action' => 'add')); return; } $plugin = $BcZip->topArchiveName; // 解凍したプラグインフォルダがキャメルケースでない場合にキャメルケースに変換 $plugin = preg_replace('/^\\s*?(creating|inflating):\\s*' . preg_quote(APP . 'Plugin' . DS, '/') . '/', '', $plugin); $plugin = explode(DS, $plugin); $plugin = $plugin[0]; $srcPluginPath = APP . 'Plugin' . DS . $plugin; $Folder = new Folder(); $Folder->chmod($srcPluginPath, 0777); $tgtPluginPath = APP . 'Plugin' . DS . Inflector::camelize($plugin); if ($srcPluginPath != $tgtPluginPath) { $Folder->move(array('to' => $tgtPluginPath, 'from' => $srcPluginPath, 'mode' => 0777)); } unlink(TMP . $zippedName); // プラグインをインストール if ($this->BcManager->installPlugin($plugin)) { clearAllCache(); $this->setMessage('新規プラグイン「' . $plugin . '」を baserCMS に登録しました。', false, true); $this->Plugin->addFavoriteAdminLink($plugin, $this->BcAuth->user()); $this->redirect(array('action' => 'index')); } else { $this->setMessage('プラグインに問題がある為インストールを完了できません。プラグインの開発者に確認してください。', true); } }
/** * testMove method * * Verify that directories and files are moved recursively * even if the destination directory already exists. * Subdirectories existing in both destination and source directory * are skipped and not merged or overwritten. * * @return void */ public function testMove() { $path = TMP . 'folder_test'; $folderOne = $path . DS . 'folder1'; $folderTwo = $folderOne . DS . 'folder2'; $folderThree = $path . DS . 'folder3'; $fileOne = $folderOne . DS . 'file1.php'; $fileTwo = $folderTwo . DS . 'file2.php'; new Folder($path, true); new Folder($folderOne, true); new Folder($folderTwo, true); new Folder($folderThree, true); touch($fileOne); touch($fileTwo); $Folder = new Folder($folderOne); $result = $Folder->move($folderThree); $this->assertTrue($result); $this->assertTrue(file_exists($folderThree . DS . 'file1.php')); $this->assertTrue(is_dir($folderThree . DS . 'folder2')); $this->assertTrue(file_exists($folderThree . DS . 'folder2' . DS . 'file2.php')); $this->assertFalse(file_exists($fileOne)); $this->assertFalse(file_exists($folderTwo)); $this->assertFalse(file_exists($fileTwo)); $Folder = new Folder($folderThree); $Folder->delete(); new Folder($folderOne, true); new Folder($folderTwo, true); touch($fileOne); touch($fileTwo); $Folder = new Folder($folderOne); $result = $Folder->move($folderThree); $this->assertTrue($result); $this->assertTrue(file_exists($folderThree . DS . 'file1.php')); $this->assertTrue(is_dir($folderThree . DS . 'folder2')); $this->assertTrue(file_exists($folderThree . DS . 'folder2' . DS . 'file2.php')); $this->assertFalse(file_exists($fileOne)); $this->assertFalse(file_exists($folderTwo)); $this->assertFalse(file_exists($fileTwo)); $Folder = new Folder($folderThree); $Folder->delete(); new Folder($folderOne, true); new Folder($folderTwo, true); new Folder($folderThree, true); new Folder($folderThree . DS . 'folder2', true); touch($fileOne); touch($fileTwo); file_put_contents($folderThree . DS . 'folder2' . DS . 'file2.php', 'untouched'); $Folder = new Folder($folderOne); $result = $Folder->move($folderThree); $this->assertTrue($result); $this->assertTrue(file_exists($folderThree . DS . 'file1.php')); $this->assertEquals('untouched', file_get_contents($folderThree . DS . 'folder2' . DS . 'file2.php')); $this->assertFalse(file_exists($fileOne)); $this->assertFalse(file_exists($folderTwo)); $this->assertFalse(file_exists($fileTwo)); $Folder = new Folder($path); $Folder->delete(); }
/** * undocumented function * * @param string $created * @return void * @access public */ function afterSave($created) { $id = $this->id; $template = $this->find('first', array('conditions' => compact('id'))); $slug = $template[__CLASS__]['slug']; $templateToCopy = false; if (isset($this->toCopy) && $this->toCopy !== false) { $templateToCopy = $this->find('first', array('conditions' => array('id' => $this->toCopy))); $this->toCopy = false; } App::import('Core', 'Folder'); $folder = new Folder(VIEWS . 'templates'); $contents = $folder->read(); $move = false; foreach ($contents[0] as $dir) { if (strpos($dir, $id) !== false) { $move = $dir; break; } } $this->path = VIEWS . 'templates' . DS . $slug . '_' . $id; if ($created) { mkdir($this->path, 0755); $imgPath = WWW_ROOT . 'img' . DS . 'templates' . DS . $slug . '_' . $id; mkdir($imgPath, 0755); // add thanks page automatically $filePath = $this->path . DS . 'thanks.ctp'; $content = "<?php echo \$this->element('../templates/default/thanks'); ?>"; file_put_contents($filePath, $content); $this->TemplateStep->create(array('template_id' => $id, 'is_thanks' => '1', 'slug' => 'thanks', 'num' => '0')); $this->TemplateStep->save(); if (!empty($templateToCopy)) { $toCopyPath = VIEWS . 'templates' . DS . $templateToCopy[__CLASS__]['slug'] . '_' . $templateToCopy[__CLASS__]['id']; $toCopyImgPath = WWW_ROOT . 'img' . DS . 'templates' . DS . $templateToCopy[__CLASS__]['slug'] . '_' . $templateToCopy[__CLASS__]['id']; $folder = new Folder($toCopyPath); $folder->copy(array('to' => $this->path)); $folder = new Folder($toCopyImgPath); $folder->copy(array('to' => $imgPath)); $this->set(array('id' => $id, 'template_step_count' => $templateToCopy[__CLASS__]['template_step_count'])); $this->save(null, false); } } else { if (!empty($move)) { $oldPath = VIEWS . 'templates' . DS . $move; $folder = new Folder($oldPath); $newPath = VIEWS . 'templates' . DS . $slug . '_' . $id; if ($newPath != $this->path) { $folder->move(array('to' => $newPath)); } } } if (isset($this->steps)) { foreach ($this->steps as $num => $content) { if ($num != 'thanks') { $filePath = $this->path . DS . 'step' . $num . '.ctp'; $stepRow = $this->TemplateStep->find('first', array('conditions' => array('template_id' => $id, 'num' => $num))); if (empty($content)) { @unlink($filePath); if (!empty($stepRow)) { $this->TemplateStep->del($stepRow['TemplateStep']['id']); } continue; } file_put_contents($filePath, $content); if (empty($stepRow)) { $this->TemplateStep->create(array('template_id' => $id, 'slug' => 'step-' . $num, 'num' => $num)); $this->TemplateStep->save(); } continue; } $filePath = $this->path . DS . 'thanks.ctp'; if (!empty($content)) { file_put_contents($filePath, $content); } } } return true; }
/** * beforeSave * * @return boolean * @access public */ public function beforeSave($options = array()) { // セーフモードの場合はフォルダの自動生成は行わない if (ini_get('safe_mode')) { return true; } // 新しいページファイルのパスを取得する $newPath = $this->createPageCategoryFolder($this->data); if ($this->exists()) { $oldPath = $this->createPageCategoryFolder($this->find('first', array('conditions' => array('id' => $this->id)))); if ($newPath != $oldPath) { $dir = new Folder(); $ret = $dir->move(array('to' => $newPath, 'from' => $oldPath, 'chmod' => 0777)); } else { if (!is_dir($newPath)) { $dir = new Folder(); $ret = $dir->create($newPath, 0777); } $ret = true; } } else { $dir = new Folder(); $ret = $dir->create($newPath, 0777); } return $ret; }
/** * Moves a file from one location to another within this plugin's namespaced storage * * @param string $filename Name of file to move * @param string $new_filename New file name to move it to * @return boolean */ public function move($filename, $new_filename) { $this->verifyStorageFolder(); $this->isValidFilename($filename); $this->isValidFilename($new_filename); if (is_dir($this->contextualize($filename))) { return Folder::move($this->contextualize($filename), $this->contextualize($new_filename)); } else { return File::move($this->contextualize($filename), $this->contextualize($new_filename)); } }
/** * Move application views files to where they now should be * * Find all view files in the folder and determine where cake expects the file to be * * @return void */ protected function _moveViewFiles() { if (!is_dir('View')) { return; } $dirs = scandir('View'); foreach ($dirs as $old) { if (!is_dir('View' . DS . $old) || $old === '.' || $old === '..') { continue; } $new = 'View' . DS . Inflector::camelize($old); $old = 'View' . DS . $old; if ($new == $old) { continue; } $this->out(__d('cake_console', 'Moving %s to %s', $old, $new)); if (!$this->params['dry-run']) { if ($this->params['git']) { exec('git mv -f ' . escapeshellarg($old) . ' ' . escapeshellarg($old . '__')); exec('git mv -f ' . escapeshellarg($old . '__') . ' ' . escapeshellarg($new)); } else { $Folder = new Folder($old); $Folder->move($new); } } } }
/** * プラグインをアップロードしてインストールする * * @return void */ public function admin_add() { $this->pageTitle = 'プラグインアップロード'; $this->subMenuElements = array('plugins'); if ($this->request->data) { if (empty($this->request->data['Plugin']['file']['tmp_name'])) { $this->setMessage('ファイルのアップロードに失敗しました。', true); } else { $name = $this->request->data['Plugin']['file']['name']; move_uploaded_file($this->request->data['Plugin']['file']['tmp_name'], TMP . $name); exec('unzip -o ' . TMP . $name . ' -d ' . APP . 'Plugin' . DS, $return); if (!empty($return[2])) { $plugin = preg_replace('/^\\s*?(creating|inflating):\\s*' . preg_quote(APP . 'Plugin' . DS, '/') . '/', '', $return[2]); $plugin = explode(DS, $plugin); $plugin = $plugin[0]; $pluginPath = BASER_THEMES . $plugin; $Folder = new Folder(); $Folder->chmod($pluginPath, 0777); $plugin = Inflector::camelize($plugin); $Folder->move(array('to' => BASER_THEMES . $plugin, 'from' => $pluginPath, 'mode' => 0777)); unlink(TMP . $name); // プラグインをインストール if ($this->BcManager->installPlugin($plugin)) { clearAllCache(); $this->setMessage('新規プラグイン「' . $plugin . '」を baserCMS に登録しました。', false, true); $this->redirect(array('action' => 'index')); } else { $this->setMessage('プラグインに問題がある為インストールを完了できません。プラグインの開発者に確認してください。', true); } } else { $msg = 'アップロードしたZIPファイルの展開に失敗しました。'; exec('unzip 2>&1', $errs); $msg .= '<br />' . implode('<br />', $errs); $this->setMessage($msg, true); $this->redirect(array('action' => 'add')); } } } }