Skip to content

Commit

Permalink
2773-basics (#2778)
Browse files Browse the repository at this point in the history
Co-authored-by: Nghiem <[email protected]>
  • Loading branch information
nghiem-mb and nghiemnv1205 authored Oct 9, 2023
1 parent b9a1077 commit 2cf739c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
20 changes: 8 additions & 12 deletions __assets/plugins/baser-core/src/basics.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
// App::uses('CakeText', 'Utility');
use Cake\Cache\Cache;
use Cake\Utility\Text;
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use BaserCore\Utility\BcFolder;
use Cake\Utility\Inflector;
use BaserCore\Utility\BcUtil;

Expand Down Expand Up @@ -183,9 +182,9 @@ function clearViewCache($url = null, $ext = '.php')
clearCache(strtolower(Text::slug($url)), 'views', $ext);
}
} else {
$folder = new Folder(CACHE . 'views' . DS);
$files = $folder->read(true, true);
foreach($files[1] as $file) {
$folder = new BcFolder(CACHE . 'views' . DS);
$files = $folder->getFiles();
foreach ($files as $file) {
if ($file != 'empty') {
@unlink(CACHE . 'views' . DS . $file);
}
Expand All @@ -200,16 +199,13 @@ function clearDataCache()
{

App::import('Core', 'Folder');
$folder = new Folder(CACHE . 'datas' . DS);
$folder = new BcFolder(CACHE . 'datas' . DS);

$files = $folder->read(true, true, true);
foreach($files[1] as $file) {
$files = $folder->getFiles();
foreach ($files as $file) {
@unlink($file);
}
$Folder = new Folder();
foreach($files[0] as $folder) {
$Folder->delete($folder);
}
$folder->delete();
}

/**
Expand Down
40 changes: 18 additions & 22 deletions __assets/plugins/baser-core/tests/TestCase/BcBasicsTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
// TODO : コード確認要
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcUtil;

return;
Expand Down Expand Up @@ -164,17 +166,17 @@ public function testClearViewCache($url, $ext)
{
$viewCachePath = CACHE . 'views' . DS;
if ($url == '/' || $url == '/index' || $url == '/index.html' || $url == '/m/' || $url == '/m/index' || $url == '/m/index.html') {
$cache = new File($viewCachePath . DS . strtolower(Inflector::slug($url)) . $ext, true);
$cache = new BcFile($viewCachePath . DS . strtolower(Inflector::slug($url)) . $ext);
// 削除実行
clearViewCache($url, $ext);

} elseif ($url) {
// ダミーのキャッシュファイルを生成
$cache = new File($viewCachePath . DS . strtolower(Inflector::slug($url)) . $ext, true);
$cacheHoge = new File($viewCachePath . DS . strtolower(Inflector::slug($url)) . '.hoge', true);
$cache = new BcFile($viewCachePath . DS . strtolower(Inflector::slug($url)) . $ext);
$cacheHoge = new BcFile($viewCachePath . DS . strtolower(Inflector::slug($url)) . '.hoge');
if (preg_match('/\/index$/', $url)) {
$replacedUrl = preg_replace('/\/index$/', '', $url);
$replacedCache = new File($viewCachePath . DS . strtolower(Inflector::slug($replacedUrl)) . $ext, true);
$replacedCache = new BcFile($viewCachePath . DS . strtolower(Inflector::slug($replacedUrl)) . $ext);
}
// 削除実行
clearViewCache($url, $ext);
Expand All @@ -191,8 +193,8 @@ public function testClearViewCache($url, $ext)

} else {
// ダミーのキャッシュファイルを生成
$cache = new File($viewCachePath . DS . 'cache', true);
$empty = new File($viewCachePath . DS . 'empty', true);
$cache = new BcFile($viewCachePath . DS . 'cache');
$empty = new BcFile($viewCachePath . DS . 'empty');

// 削除実行
clearViewCache($url, $ext);
Expand Down Expand Up @@ -240,26 +242,20 @@ public function testClearAllCache()
$envConf = Cache::config('_bc_env_');
$envConf = $envConf['settings'];

$coreCache = new File($coreConf['path'] . $coreConf['prefix'] . 'cache', true);
$modelCache = new File($modelConf['path'] . $modelConf['prefix'] . 'cache', true);
$envCache = new File($envConf['path'] . $envConf['prefix'] . 'cache', true);
$viewCache = new File(CACHE . 'views' . DS . 'cache', true);
$dataCache = new File(CACHE . 'datas' . DS . 'cache', true);
$coreCache = new BcFile($coreConf['path'] . $coreConf['prefix'] . 'cache');
$modelCache = new BcFile($modelConf['path'] . $modelConf['prefix'] . 'cache');
$envCache = new BcFile($envConf['path'] . $envConf['prefix'] . 'cache');
$viewCache = new BcFile(CACHE . 'views' . DS . 'cache');
$dataCache = new BcFile(CACHE . 'datas' . DS . 'cache');

// キャッシュ削除
BcUtil::clearAllCache();

$this->assertFalse($coreCache->exists());
$this->assertFalse($modelCache->exists());
$this->assertFalse($envCache->exists());
$this->assertFalse($viewCache->exists());
$this->assertFalse($dataCache->exists());

$coreCache->close();
$modelCache->close();
$envCache->close();
$viewCache->close();
$dataCache->close();
$this->assertFalse(is_file($coreCache->getPath()));
$this->assertFalse(is_file($modelCache->getPath()));
$this->assertFalse(is_file($envCache->getPath()));
$this->assertFalse(is_file($viewCache->getPath()));
$this->assertFalse(is_file($dataCache->getPath()));
}

/**
Expand Down

0 comments on commit 2cf739c

Please sign in to comment.