Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PluginsService and PluginsServiceTest #2845

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions plugins/baser-core/src/Service/PluginsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
use BaserCore\Model\Entity\Plugin;
use BaserCore\Model\Table\PluginsTable;
use BaserCore\Utility\BcContainerTrait;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcFolder;
use BaserCore\Utility\BcSiteConfig;
use BaserCore\Utility\BcUpdateLog;
use BaserCore\Utility\BcZip;
use Cake\Cache\Cache;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Filesystem\File;
use Cake\Http\Client;
use Cake\Http\Client\Exception\NetworkException;
use Cake\ORM\TableRegistry;
Expand All @@ -29,7 +30,6 @@
use Cake\Core\Configure;
use BaserCore\Utility\BcUtil;
use Cake\Core\App;
use Cake\Filesystem\Folder;
use Cake\Core\Plugin as CakePlugin;
use Cake\Datasource\EntityInterface;
use Cake\Utility\Xml;
Expand Down Expand Up @@ -109,9 +109,9 @@ public function getIndex(string $sortMode): array
}
$paths = App::path('plugins');
foreach($paths as $path) {
$Folder = new Folder($path);
$files = $Folder->read(true, true, true);
foreach($files[0] as $file) {
$Folder = new BcFolder($path);
$files = $Folder->getFolders(['full'=>true]);
foreach($files as $file) {
$name = Inflector::camelize(Inflector::underscore(basename($file)));
if (in_array(Inflector::camelize(basename($file), '-'), Configure::read('BcApp.core'))) continue;
if (in_array($name, $registeredName)) {
Expand Down Expand Up @@ -657,8 +657,8 @@ public function add(array $postData)
$num++;
$dstName = Inflector::camelize($baseName) . $num;
}
$folder = new Folder(TMP . $srcName);
$folder->move(BASER_PLUGINS . $dstName, ['mode' => 0777]);
$folder = new BcFolder(TMP . $srcName);
$folder->move(TMP . $srcName, BASER_PLUGINS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nghiem-mb $dstName の追加が必要そう

unlink(TMP . $name);
BcUtil::changePluginNameSpace($dstName);
return $dstName;
Expand Down Expand Up @@ -694,7 +694,7 @@ public function getAvailableCoreVersionInfo()
$body = $response->getStringBody();
} catch (InvalidArgumentException $e) {
// ユニットテストの場合にhttpでアクセスできないので、ファイルから直接読み込む
$file = new File($releaseUrl);
$file = new BcFile($releaseUrl);
$body = $file->read();
} catch (NetworkException $e) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
use Cake\Filesystem\Folder;
use Cake\TestSuite\IntegrationTestTrait;
use Composer\Package\Archiver\ZipArchiver;

Expand Down
30 changes: 17 additions & 13 deletions plugins/baser-core/tests/TestCase/Service/PluginsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use BaserCore\Test\Factory\PluginFactory;
use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcFile;
use BaserCore\Utility\BcFolder;
use BaserCore\Utility\BcUtil;
use Cake\Cache\Cache;
use Cake\Core\Configure;
Expand Down Expand Up @@ -388,9 +390,10 @@ public function test_add()
{
$path = BASER_PLUGINS . 'BcThemeSample';
$zipSrcPath = TMP . 'zip' . DS;
$folder = new Folder();
$folder->create($zipSrcPath, 0777);
$folder->copy($zipSrcPath . 'BcThemeSample2', ['from' => $path, 'mode' => 0777]);
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nghiem-mb BcFolder::copyの仕組みが問題ないか確認します。

rename($zipSrcPath. 'BcThemeSample',$zipSrcPath. 'BcThemeSample2');
$plugin = 'BcThemeSample2';
$zip = new ZipArchiver();
$testFile = $zipSrcPath . $plugin . '.zip';
Expand All @@ -415,8 +418,9 @@ public function test_add()
$this->assertTrue(is_dir(ROOT . DS . 'plugins' . DS . $plugin));

// 既に /plugins/ 内に同名のプラグインが存在する場合には、数字付きのディレクトリ名(PluginName2)にリネームする。
$folder->create($zipSrcPath, 0777);
$folder->copy($zipSrcPath . 'BcThemeSample2', ['from' => $path, 'mode' => 0777]);
$folder = new BcFolder($zipSrcPath);
$folder->create();
$folder->copy($path, $zipSrcPath . 'BcThemeSample2');
$zip = new ZipArchiver();
$zip->archive($zipSrcPath, $testFile, true);
$this->setUploadFileToRequest('file', $testFile);
Expand All @@ -432,10 +436,12 @@ public function test_add()
$this->assertEquals('BcThemeSample3', $rs);

//テスト実行後不要ファイルを削除
$folder = new Folder();
$folder->delete(ROOT . DS . 'plugins' . DS . $plugin);
$folder->delete(ROOT . DS . 'plugins' . DS . 'BcThemeSample22');
$folder->delete($zipSrcPath);
$folder = new BcFolder(ROOT . DS . 'plugins' . DS . $plugin);
$folder->delete();
$folder = new BcFolder(ROOT . DS . 'plugins' . DS . 'BcThemeSample22');
$folder->delete();
$folder = new BcFolder($zipSrcPath);
$folder->delete();

// TODO ローカルでは成功するが、GitHubActions上でうまくいかないためコメントアウト(原因不明)
// post_max_size を超えた場合、サーバーに設定されているサイズ制限を超えた場合、
Expand Down Expand Up @@ -479,9 +485,8 @@ public function test_getAvailableCoreVersionInfo(
// BcApp.coreReleaseUrl を書き換える
Configure::write('BcApp.coreReleaseUrl', $rssPath);
// バージョンを書き換える
$file = new File($versionPath);
$file = new BcFile($versionPath);
$file->write($currentVersion);
$file->close();
// RSSを生成
$this->createReleaseRss($releaseVersions);
// キャッシュを削除
Expand Down Expand Up @@ -551,9 +556,8 @@ public function createReleaseRss(array $versions)
</channel>
</rss>
EOF;
$file = new File($url);
$file = new BcFile($url);
$file->write($rss);
$file->close();
}

}