Skip to content

Commit 4cf41ec

Browse files
author
Praesidiarius
committed
new plugin setup
1 parent 6066c8b commit 4cf41ec

File tree

5 files changed

+189
-2
lines changed

5 files changed

+189
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "oneplace/oneplace-contact-address",
33
"description": "onePlace Contact Address Plugin. Multiple Addresses for Contacts",
44
"type": "oneplace-plugin",
5-
"version": "1.0.2",
5+
"version": "1.0.3",
66
"license": "BSD-3-Clause",
77
"keywords": [
88
"laminas",

config/module.config.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
use Laminas\ServiceManager\Factory\InvokableFactory;
2121

2222
return [
23+
# Skeleton Module - Routes
24+
'router' => [
25+
'routes' => [
26+
'contact-address-setup' => [
27+
'type' => Literal::class,
28+
'options' => [
29+
'route' => '/contact/address/setup',
30+
'defaults' => [
31+
'controller' => Controller\InstallController::class,
32+
'action' => 'checkdb',
33+
],
34+
],
35+
],
36+
],
37+
],
38+
2339
# View Settings
2440
'view_manager' => [
2541
'template_path_stack' => [
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* InstallController.php - Main Controller
4+
*
5+
* Installer for Plugin
6+
*
7+
* @category Controller
8+
* @package Contact\Address
9+
* @author Verein onePlace
10+
* @copyright (C) 2020 Verein onePlace <[email protected]>
11+
* @license https://opensource.org/licenses/BSD-3-Clause
12+
* @version 1.0.0
13+
* @since 1.0.0
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
namespace OnePlace\Contact\Address\Controller;
19+
20+
use Application\Controller\CoreUpdateController;
21+
use Application\Model\CoreEntityModel;
22+
use OnePlace\Contact\Address\Model\AddressTable;
23+
use Laminas\View\Model\ViewModel;
24+
use Laminas\Db\Adapter\AdapterInterface;
25+
use Laminas\Db\TableGateway\TableGateway;
26+
use Laminas\Db\ResultSet\ResultSet;
27+
28+
class InstallController extends CoreUpdateController {
29+
/**
30+
* SkeletonController constructor.
31+
*
32+
* @param AdapterInterface $oDbAdapter
33+
* @param SkeletonTable $oTableGateway
34+
* @since 1.0.0
35+
*/
36+
public function __construct(AdapterInterface $oDbAdapter, AddressTable $oTableGateway, $oServiceManager)
37+
{
38+
$this->oTableGateway = $oTableGateway;
39+
$this->sSingleForm = 'contactaddress-single';
40+
parent::__construct($oDbAdapter, $oTableGateway, $oServiceManager);
41+
42+
if ($oTableGateway) {
43+
# Attach TableGateway to Entity Models
44+
if (! isset(CoreEntityModel::$aEntityTables[$this->sSingleForm])) {
45+
CoreEntityModel::$aEntityTables[$this->sSingleForm] = $oTableGateway;
46+
}
47+
}
48+
}
49+
50+
public function checkdbAction()
51+
{
52+
# Set Layout based on users theme
53+
$this->setThemeBasedLayout('contact');
54+
55+
$oRequest = $this->getRequest();
56+
57+
if(! $oRequest->isPost()) {
58+
59+
$bTableExists = false;
60+
61+
try {
62+
$this->oTableGateway->fetchAll(false);
63+
$bTableExists = true;
64+
} catch (\RuntimeException $e) {
65+
66+
}
67+
68+
return new ViewModel([
69+
'bTableExists' => $bTableExists,
70+
'sVendor' => 'oneplace',
71+
'sModule' => 'oneplace-contact-address',
72+
]);
73+
} else {
74+
$sSetupConfig = $oRequest->getPost('plc_module_setup_config');
75+
76+
$sSetupFile = 'vendor/oneplace/oneplace-contact-address/data/install.sql';
77+
if(file_exists($sSetupFile)) {
78+
echo 'got install file..';
79+
$this->parseSQLInstallFile($sSetupFile,CoreUpdateController::$oDbAdapter);
80+
}
81+
82+
if($sSetupConfig != '') {
83+
$sConfigStruct = 'vendor/oneplace/oneplace-contact-address/data/structure_'.$sSetupConfig.'.sql';
84+
if(file_exists($sConfigStruct)) {
85+
echo 'got struct file for config '.$sSetupConfig;
86+
$this->parseSQLInstallFile($sConfigStruct,CoreUpdateController::$oDbAdapter);
87+
}
88+
$sConfigData = 'vendor/oneplace/oneplace-contact-address/data/data_'.$sSetupConfig.'.sql';
89+
if(file_exists($sConfigData)) {
90+
echo 'got data file for config '.$sSetupConfig;
91+
$this->parseSQLInstallFile($sConfigData,CoreUpdateController::$oDbAdapter);
92+
}
93+
}
94+
95+
$oModTbl = new TableGateway('core_module', CoreUpdateController::$oDbAdapter);
96+
$oModTbl->insert([
97+
'module_key' => 'oneplace-contact-address',
98+
'type' => 'plugin',
99+
'version' => \OnePlace\Contact\Address\Module::VERSION,
100+
'label' => 'onePlace Contact Address',
101+
'vendor' => 'oneplace',
102+
]);
103+
104+
try {
105+
$this->oTableGateway->fetchAll(false);
106+
$bTableExists = true;
107+
} catch (\RuntimeException $e) {
108+
109+
}
110+
$bTableExists = false;
111+
112+
$this->flashMessenger()->addSuccessMessage('Contact Address DB Update successful');
113+
$this->redirect()->toRoute('application', ['action' => 'checkforupdates']);
114+
}
115+
}
116+
}

src/Module.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Module {
3232
*
3333
* @since 1.0.0
3434
*/
35-
const VERSION = '1.0.2';
35+
const VERSION = '1.0.3';
3636

3737
/**
3838
* Load module config file
@@ -100,6 +100,15 @@ public function getControllerConfig() : array {
100100
$container
101101
);
102102
},
103+
# Installer
104+
Controller\InstallController::class => function($container) {
105+
$oDbAdapter = $container->get(AdapterInterface::class);
106+
return new Controller\InstallController(
107+
$oDbAdapter,
108+
$container->get(Model\AddressTable::class),
109+
$container
110+
);
111+
},
103112
],
104113
];
105114
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<div class="row">
2+
<div class="col-md-12">
3+
<div class="card">
4+
<div class="card-header">
5+
<h2>Check for installation</h2>
6+
</div>
7+
<div class="card-body">
8+
<form action="" method="POST">
9+
<div class="form-group">
10+
<?php
11+
?>
12+
<?php
13+
if($bTableExists) { ?>
14+
<div class="alert alert-success py-2 px-2">
15+
<?=$this->translate('Database is up-to-date')?>
16+
</div>
17+
<?php
18+
} else { ?>
19+
<div class="alert alert-warning py-2 px-2">
20+
<?=$this->translate('Database needs update. Please choose config')?>
21+
</div>
22+
<?php
23+
if(file_exists('vendor/'.$sVendor.'/'.$sModule.'/data/structure_simple.sql')) {
24+
?> <br/><input type="radio" name="plc_module_setup_config" value="simple" checked /> Simple
25+
<?php
26+
}
27+
if(file_exists('vendor/'.$sVendor.'/'.$sModule.'/data/structure_extended.sql')) {
28+
?> <br/><input type="radio" name="plc_module_setup_config" value="extended" /> Simple
29+
<?php
30+
}
31+
}
32+
?>
33+
</div>
34+
35+
<?php if (! $bTableExists) { ?>
36+
<div class="form-group">
37+
<button type="submit" class="btn btn-primary">
38+
<?=$this->translate('Update Database')?>
39+
</button>
40+
</div>
41+
<?php } ?>
42+
</form>
43+
</div>
44+
</div>
45+
</div>
46+
</div>

0 commit comments

Comments
 (0)