Skip to content

Commit 4ccca5c

Browse files
テーマをコピーした際にヘルパーの重複エラーが表示される fix #3978
1 parent ae10652 commit 4ccca5c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

plugins/baser-core/src/Service/ThemesService.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Cake\Routing\Router;
3333
use Cake\Utility\Inflector;
3434
use Laminas\Diactoros\UploadedFile;
35+
use BaserCore\Utility\BcFile;
3536

3637
/**
3738
* ThemesService
@@ -362,6 +363,47 @@ public function loadDefaultDataPattern(string $currentTheme, string $dbDataPatte
362363
return $result;
363364
}
364365

366+
/**
367+
* ヘルパーのnamespaceを変更する
368+
*/
369+
public function changeHelperNameSpace($newTheme)
370+
{
371+
$pluginPath = BcUtil::getPluginPath($newTheme);
372+
if (!$pluginPath) return false;
373+
if (file_exists($pluginPath . 'src' . DS .'View' . DS .'Helper'. DS . $newTheme. 'Helper.php')) {
374+
$helperClassPath = $pluginPath . 'src' . DS .'View' . DS .'Helper'. DS . $newTheme. 'Helper.php';
375+
}else{
376+
return false;
377+
}
378+
$file = new BcFile($helperClassPath);
379+
$data = $file->read();
380+
$file->write(preg_replace('/namespace .+?;/', 'namespace ' . $newTheme . '\View\Helper;', $data));
381+
return true;
382+
}
383+
384+
/**
385+
* ヘルパーのクラス名を変更する
386+
*/
387+
public function ChangeHelperClassName($oldTheme,$newTheme)
388+
{
389+
$pluginPath = BcUtil::getPluginPath($newTheme);
390+
if (!$pluginPath) return false;
391+
$oldPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $oldTheme . 'Helper.php';
392+
$newPath = $pluginPath . 'src'. DS .'View' . DS .'Helper' . DS . $newTheme . 'Helper.php';
393+
if(!file_exists($newPath))
394+
{
395+
if(file_exists($oldPath)) {
396+
rename($oldPath, $newPath);
397+
} else {
398+
return false;
399+
}
400+
}
401+
$file = new BcFile($newPath);
402+
$data = $file->read();
403+
$file->write(preg_replace('/class\s+.*?Helper/', 'class ' . $newTheme . 'Helper', $data));
404+
return true;
405+
}
406+
365407
/**
366408
* コピーする
367409
*
@@ -399,6 +441,8 @@ public function copy(string $theme): bool
399441
}
400442
BcUtil::changePluginClassName($oldTheme, $newTheme);
401443
BcUtil::changePluginNameSpace($newTheme);
444+
$this->ChangeHelperClassName($oldTheme,$newTheme);
445+
$this->changeHelperNameSpace($newTheme);
402446
return true;
403447
}
404448

0 commit comments

Comments
 (0)