Skip to content

Commit

Permalink
Merge pull request opencart#13602 from mhcwebdesign/3.0.x.x
Browse files Browse the repository at this point in the history
extensions uninstall fixes: remove permissions, + fixes for phpstan.neon
  • Loading branch information
mhcwebdesign authored Jan 26, 2024
2 parents de1c968 + 58c3c9d commit b30bf19
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 125 deletions.
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ parameters:
- ./upload/
excludePaths:
- ./system/storage/vendor/
- ./system/storage/cache/template/
- ./upload/system/storage/vendor/
- ./upload/system/storage/cache/template/
tmpDir: .cache
ignoreErrors:
- '#Class Event constructor invoked with 1 parameter, 4-5 required\.#'
254 changes: 129 additions & 125 deletions upload/admin/controller/extension/extension/advertise.php
Original file line number Diff line number Diff line change
@@ -1,134 +1,138 @@
<?php
class ControllerExtensionExtensionAdvertise extends Controller {
private $error = array();
private $error = array();

public function index() {
$this->load->language('extension/extension/advertise');
public function index() {
$this->load->language('extension/extension/advertise');

$this->load->model('setting/extension');
$this->load->model('setting/extension');

$this->getList();
}
$this->getList();
}

public function install() {
$this->load->language('extension/extension/advertise');
public function install() {
$this->load->language('extension/extension/advertise');

$this->load->model('setting/extension');
$this->load->model('setting/extension');

if ($this->validate()) {
$this->model_setting_extension->install('advertise', $this->request->get['extension']);

$this->load->model('user/user_group');

$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/advertise/' . $this->request->get['extension']);
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/advertise/' . $this->request->get['extension']);

// Compatibility
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'advertise/' . $this->request->get['extension']);
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'advertise/' . $this->request->get['extension']);

// Call install method if it exsits
$this->load->controller('extension/advertise/' . $this->request->get['extension'] . '/install');

$this->session->data['success'] = $this->language->get('text_success');
}

$this->getList();
}

public function uninstall() {
$this->load->language('extension/extension/advertise');

$this->load->model('setting/extension');

if ($this->validate()) {
$this->model_setting_extension->uninstall('advertise', $this->request->get['extension']);

// Call uninstall method if it exsits
$this->load->controller('extension/advertise/' . $this->request->get['extension'] . '/uninstall');

$this->session->data['success'] = $this->language->get('text_success');
}

$this->getList();
}

protected function getList() {
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}

if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];

unset($this->session->data['success']);
} else {
$data['success'] = '';
}

$extensions = $this->model_setting_extension->getInstalled('advertise');

foreach ($extensions as $key => $value) {
if (!is_file(DIR_APPLICATION . 'controller/extension/advertise/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/advertise/' . $value . '.php')) {
$this->model_setting_extension->uninstall('advertise', $value);

unset($extensions[$key]);
}
}

$this->load->model('setting/store');
$this->load->model('setting/setting');

$stores = $this->model_setting_store->getStores();

$data['extensions'] = array();

// Compatibility code for old extension folders
$files = glob(DIR_APPLICATION . 'controller/extension/advertise/*.php');

if ($files) {
foreach ($files as $file) {
$extension = basename($file, '.php');

// Compatibility code for old extension folders
$this->load->language('extension/advertise/' . $extension, 'extension');

$store_data = array();

$store_data[] = array(
'name' => $this->config->get('config_name'),
'edit' => $this->url->link('extension/advertise/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=0', true),
'status' => $this->config->get('advertise_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled')
);

foreach ($stores as $store) {
$store_data[] = array(
'name' => $store['name'],
'edit' => $this->url->link('extension/advertise/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id'], true),
'status' => $this->model_setting_setting->getSettingValue('advertise_' . $extension . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled')
);
}

$data['extensions'][] = array(
'name' => $this->language->get('extension')->get('heading_title'),
'install' => $this->url->link('extension/extension/advertise/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true),
'uninstall' => $this->url->link('extension/extension/advertise/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true),
'installed' => in_array($extension, $extensions),
'store' => $store_data
);
}
}

$this->response->setOutput($this->load->view('extension/extension/advertise', $data));
}

protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/extension/advertise')) {
$this->error['warning'] = $this->language->get('error_permission');
}

return !$this->error;
}
if ($this->validate()) {
$this->model_setting_extension->install('advertise', $this->request->get['extension']);

$this->load->model('user/user_group');

$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/advertise/' . $this->request->get['extension']);
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/advertise/' . $this->request->get['extension']);

// Compatibility
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'advertise/' . $this->request->get['extension']);
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'advertise/' . $this->request->get['extension']);

// Call install method if it exsits
$this->load->controller('extension/advertise/' . $this->request->get['extension'] . '/install');

$this->session->data['success'] = $this->language->get('text_success');
}

$this->getList();
}

public function uninstall() {
$this->load->language('extension/extension/advertise');

$this->load->model('setting/extension');

if ($this->validate()) {
$this->model_setting_extension->uninstall('advertise', $this->request->get['extension']);

// Call uninstall method if it exsits
$this->load->controller('extension/advertise/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/advertise/' . $this->request->get['extension']);
$this->model_user_user_group->removePermissions('advertise/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

$this->getList();
}

protected function getList() {
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}

if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];

unset($this->session->data['success']);
} else {
$data['success'] = '';
}

$extensions = $this->model_setting_extension->getInstalled('advertise');

foreach ($extensions as $key => $value) {
if (!is_file(DIR_APPLICATION . 'controller/extension/advertise/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/advertise/' . $value . '.php')) {
$this->model_setting_extension->uninstall('advertise', $value);

unset($extensions[$key]);
}
}

$this->load->model('setting/store');
$this->load->model('setting/setting');

$stores = $this->model_setting_store->getStores();

$data['extensions'] = array();

// Compatibility code for old extension folders
$files = glob(DIR_APPLICATION . 'controller/extension/advertise/*.php');

if ($files) {
foreach ($files as $file) {
$extension = basename($file, '.php');

// Compatibility code for old extension folders
$this->load->language('extension/advertise/' . $extension, 'extension');

$store_data = array();

$store_data[] = array(
'name' => $this->config->get('config_name'),
'edit' => $this->url->link('extension/advertise/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=0', true),
'status' => $this->config->get('advertise_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled')
);

foreach ($stores as $store) {
$store_data[] = array(
'name' => $store['name'],
'edit' => $this->url->link('extension/advertise/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id'], true),
'status' => $this->model_setting_setting->getSettingValue('advertise_' . $extension . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled')
);
}

$data['extensions'][] = array(
'name' => $this->language->get('extension')->get('heading_title'),
'install' => $this->url->link('extension/extension/advertise/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true),
'uninstall' => $this->url->link('extension/extension/advertise/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true),
'installed' => in_array($extension, $extensions),
'store' => $store_data
);
}
}

$this->response->setOutput($this->load->view('extension/extension/advertise', $data));
}

protected function validate() {
if (!$this->user->hasPermission('modify', 'extension/extension/advertise')) {
$this->error['warning'] = $this->language->get('error_permission');
}

return !$this->error;
}
}
4 changes: 4 additions & 0 deletions upload/admin/controller/extension/extension/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/analytics/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/analytics/' . $this->request->get['extension']);
$this->model_user_user_group->removePermissions('analytics/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
4 changes: 4 additions & 0 deletions upload/admin/controller/extension/extension/captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/captcha/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/captcha/' . $this->request->get['extension']);
$this->model_user_user_group->removePermissions('captcha/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/currency/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/currency/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/dashboard/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/dashboard/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/feed/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/feed/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/fraud.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/fraud/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/fraud/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/menu/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/menu/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/module/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/module/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/payment/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/payment/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public function uninstall() {

$this->load->controller('extension/report/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/report/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/shipping/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/shipping/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
3 changes: 3 additions & 0 deletions upload/admin/controller/extension/extension/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public function uninstall() {
// Call uninstall method if it exsits
$this->load->controller('extension/theme/' . $this->request->get['extension'] . '/uninstall');

$this->load->model('user/user_group');
$this->model_user_user_group->removePermissions('extension/theme/' . $this->request->get['extension']);

$this->session->data['success'] = $this->language->get('text_success');
}

Expand Down
Loading

0 comments on commit b30bf19

Please sign in to comment.