Skip to content

Commit 2e6542a

Browse files
应用插件部分
1 parent b3d5efd commit 2e6542a

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

services/extension/Administer.php

+26-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class Administer extends Service
2323
// 卸载应用,是否删除掉应用的文件夹
2424
public $uninstallRemoveFile = true;
2525

26+
public $currentNamespace;
27+
2628
/**
2729
* 1.插件的安装
2830
* @param $extension_name | string , 插件名称(唯一)
@@ -39,6 +41,7 @@ public function install($extension_namespace, $forceInstall=false)
3941

4042
return false;
4143
}
44+
$this->currentNamespace = $extension_namespace;
4245
// 插件已经安装
4346
$installed_status = $modelOne['installed_status'];
4447
if (!$forceInstall && Yii::$service->extension->isInstalledStatus($installed_status)) {
@@ -93,7 +96,7 @@ public function testInstall($extension_namespace, $forceInstall=false)
9396

9497
return false;
9598
}
96-
99+
$this->currentNamespace = $extension_namespace;
97100
// 通过数据库找到应用的配置文件路径
98101
$extensionConfigFile = Yii::getAlias($modelOne['config_file_path']);
99102
if (!file_exists($extensionConfigFile)) {
@@ -144,6 +147,7 @@ public function upgrade($extension_namespace)
144147

145148
return false;
146149
}
150+
$this->currentNamespace = $extension_namespace;
147151
// 插件如果没有安装
148152
$installed_status = $modelOne['installed_status'];
149153
if (!Yii::$service->extension->isInstalledStatus($installed_status)) {
@@ -369,13 +373,30 @@ protected function installDbData($modelOne)
369373

370374

371375
// theme文件进行copy到@app/theme/base/addons 下面。
372-
protected function copyThemeFile($modelOne)
376+
protected function copyThemeFile($sourcePath)
373377
{
378+
if (!$this->currentNamespace) {
379+
Yii::$service->helper->errors->add('copyThemeFile: current extension: {namespace} is not exist', ['namespace' =>$this->currentNamespace ]);
380+
381+
return false;
382+
}
383+
$targetPath = Yii::getAlias('@appimage/common/addons/'.$this->currentNamespace);
374384

375-
376-
385+
Yii::$service->helper->copyDirImage($sourcePath, $targetPath);
377386

378387
}
379388

380-
389+
// theme文件进行copy到@app/theme/base/addons 下面。
390+
protected function removeThemeFile()
391+
{
392+
if (!$this->currentNamespace) {
393+
Yii::$service->helper->errors->add('copyThemeFile: current extension: {namespace} is not exist', ['namespace' =>$this->currentNamespace ]);
394+
395+
return false;
396+
}
397+
$sourcePath = Yii::getAlias('@appimage/common/addons/'.$this->currentNamespace);
398+
Yii::$service->helper->deleteDir($sourcePath);
399+
400+
return true;
401+
}
381402
}

services/extension/generate/administer/Install.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,14 @@ public function installDbSql()
9898
}
9999

100100
/**
101-
* 复制图片文件到appimage,如果存在,则会被强制覆盖
102-
* 模板应用一般会用到改函数
101+
* 复制图片文件到appimage/common/addons/{namespace},如果存在,则会被强制覆盖
103102
*/
104103
public function copyImageFile()
105104
{
106105
/*
107-
$sourcePath = Yii::getAlias('@<?= $namespaces ?>/app/appimage');
108-
$targetPath = Yii::getAlias('@appimage');
109-
// 只复制产品文件到appimage,其他的文件将会被过滤掉。(安全)
110-
Yii::$service->helper->copyDirImage($sourcePath, $targetPath);
106+
$sourcePath = Yii::getAlias('@<?= $namespaces ?>/app/appimage/common/addons/<?= $namespaces ?>');
107+
108+
Yii::$service->extension->administer->copyThemeFile($sourcePath);
111109
*/
112110
return true;
113111
}

services/extension/generate/administer/Uninstall.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public function uninstallDbSql()
4848
public function removeImageFile()
4949
{
5050
/*
51-
$targetPath = Yii::getAlias('@appimage/common/appfront/media/fect/xxxxxxxxx');
52-
Yii::$service->helper->deleteDir($targetPath);
51+
return Yii::$service->extension->administer->removeThemeFile();
5352
*/
5453

5554
return true;

services/extension/generate/administer/Upgrade.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,17 @@ public function upgrade103()
7777
}
7878

7979
/**
80-
* 复制图片文件到appimage,如果存在,则会被强制覆盖
81-
* 如果更新的版本中有新增的图片,可以执行copy image
80+
* 复制图片文件到appimage/common/addons/{namespace},如果存在,则会被强制覆盖
8281
*/
8382
public function copyImageFile()
8483
{
8584
/*
86-
$sourcePath = Yii::getAlias('@<?= $namespaces ?>/app/appimage');
87-
$targetPath = Yii::getAlias('@appimage');
88-
// 只复制产品文件到appimage,其他的文件将会被过滤掉。(安全)
89-
Yii::$service->helper->copyDirImage($sourcePath, $targetPath);
85+
$sourcePath = Yii::getAlias('@<?= $namespaces ?>/app/appimage/common/addons/<?= $namespaces ?>');
86+
87+
Yii::$service->extension->administer->copyThemeFile($sourcePath);
9088
*/
9189
return true;
9290
}
9391

9492

95-
96-
9793
}

0 commit comments

Comments
 (0)