/** * フォルダの中をフォルダを残して空にする * * @param string $path * @return boolean */ function emptyFolder($path) { $result = true; $Folder = new Folder($path); $files = $Folder->read(true, true, true); if (is_array($files[1])) { foreach ($files[1] as $file) { if ($file != 'empty') { if (!@unlink($file)) { $result = false; } } } } if (is_array($files[0])) { foreach ($files[0] as $file) { if (!emptyFolder($file)) { $result = false; } } } return $result; }
/** * スキーマ用の一時フォルダをリセットする * * @return boolean * @access protected */ protected function _resetTmpSchemaFolder() { $path = TMP . 'schemas' . DS; return emptyFolder($path); }
/** * 初期データセットをダウンロードする */ public function admin_download_default_data_pattern() { /* コアのCSVを生成 */ $tmpDir = TMP . 'csv' . DS; $Folder = new Folder(); $Folder->create($tmpDir); emptyFolder($tmpDir); clearAllCache(); $excludes = array('plugins', 'dblogs', 'users', 'favorites'); $this->_writeCsv('baser', 'core', $tmpDir, $excludes); /* プラグインのCSVを生成 */ $plugins = CakePlugin::loaded(); foreach ($plugins as $plugin) { $Folder->create($tmpDir . $plugin); emptyFolder($tmpDir . $plugin); $this->_writeCsv('plugin', $plugin, $tmpDir . $plugin . DS); } /* site_configsの編集 (email / google_analytics_id / version) */ $targets = array('email', 'google_analytics_id', 'version'); $path = $tmpDir . 'site_configs.csv'; $fp = fopen($path, 'a+'); $records = array(); while (($record = fgetcsvReg($fp, 10240)) !== false) { if (in_array($record[1], $targets)) { $record[2] = ''; } $records[] = '"' . implode('","', $record) . '"'; } ftruncate($fp, 0); fwrite($fp, implode("\n", $records)); /* ZIPに固めてダウンロード */ $fileName = 'default'; $Simplezip = new Simplezip(); $Simplezip->addFolder($tmpDir); $Simplezip->download($fileName); emptyFolder($tmpDir); exit; }
/** * フォルダの中をフォルダを残して空にする */ public function testEmptyFolder() { $dummyPath = TMP . 'test' . DS; $names = array('folder' => array('folder1', 'folder2'), 'file' => array('file1', 'file2')); // ダミーのフォルダとファイルを作成 $Folder = new Folder(); $Folder->create($dummyPath, 0755); $Folder->create($dummyPath . $names['folder'][0], 0755); $Folder->create($dummyPath . $names['folder'][1], 0755); $File1 = new File($dummyPath . $names['file'][0], true); $File2 = new File($dummyPath . $names['file'][1], true); emptyFolder($dummyPath); $result = true; // フォルダが存在しているかチェック foreach ($names['folder'] as $key => $name) { if (!is_dir($dummyPath . $name)) { $result = false; } @rmdir($dummyPath . $name); } // ファイルが削除されているかチェック foreach ($names['file'] as $key => $name) { if (file_exists($dummyPath . $name)) { $result = false; } @unlink($dummyPath . $name); } $Folder->delete($dummyPath); $this->assertTrue($result, 'フォルダの中のファイルのみを削除することができません'); }
<?php $loader = (require 'vendor/autoload.php'); include 'vendor/composer/autoload_classmap.php'; define('FOLDER_CADENZA', $baseDir . '/vendor.src'); emptyFolder(FOLDER_CADENZA); $packages = packages($loader); foreach ($packages as $preffix => $paths) { $package = package($preffix); $folder = FOLDER_CADENZA . "/{$package}"; if (count($paths) > 1) { readfile(__DIR__ . '/message.txt'); exit; } $path = $paths[0]; if (inVendor($path)) { createLink($path, $folder); } } function packages($loader) { $methods = array('getPrefixes', 'getPrefixesPsr4', 'getFallbackDirs', 'getFallbackDirsPsr4', 'getClassMap'); $result = array(); foreach ($methods as $method) { if ($paths = $loader->{$method}()) { $result = array_merge($result, $paths); } } return $result; } function package($preffix)