-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
205 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* InstallController.php - Main Controller | ||
* | ||
* Installer for Plugin | ||
* | ||
* @category Controller | ||
* @package Article\History | ||
* @author Verein onePlace | ||
* @copyright (C) 2020 Verein onePlace <admin@1plc.ch> | ||
* @license https://opensource.org/licenses/BSD-3-Clause | ||
* @version 1.0.0 | ||
* @since 1.0.1 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OnePlace\Article\History\Controller; | ||
|
||
use Application\Controller\CoreUpdateController; | ||
use Application\Model\CoreEntityModel; | ||
use OnePlace\Article\History\Model\HistoryTable; | ||
use Laminas\View\Model\ViewModel; | ||
use Laminas\Db\Adapter\AdapterInterface; | ||
use Laminas\Db\TableGateway\TableGateway; | ||
use Laminas\Db\ResultSet\ResultSet; | ||
|
||
class InstallController extends CoreUpdateController { | ||
/** | ||
* InstallController constructor. | ||
* | ||
* @param AdapterInterface $oDbAdapter | ||
* @param HistoryTable $oTableGateway | ||
* @since 1.0.0 | ||
*/ | ||
public function __construct(AdapterInterface $oDbAdapter, HistoryTable $oTableGateway, $oServiceManager) | ||
{ | ||
$this->oTableGateway = $oTableGateway; | ||
$this->sSingleForm = 'articlehistory-single'; | ||
parent::__construct($oDbAdapter, $oTableGateway, $oServiceManager); | ||
|
||
if ($oTableGateway) { | ||
# Attach TableGateway to Entity Models | ||
if (! isset(CoreEntityModel::$aEntityTables[$this->sSingleForm])) { | ||
CoreEntityModel::$aEntityTables[$this->sSingleForm] = $oTableGateway; | ||
} | ||
} | ||
} | ||
|
||
public function checkdbAction() | ||
{ | ||
# Set Layout based on users theme | ||
$this->setThemeBasedLayout('article'); | ||
|
||
$oRequest = $this->getRequest(); | ||
|
||
if(! $oRequest->isPost()) { | ||
|
||
$bTableExists = false; | ||
|
||
try { | ||
$this->oTableGateway->fetchAll(false); | ||
$bTableExists = true; | ||
} catch (\RuntimeException $e) { | ||
|
||
} | ||
|
||
return new ViewModel([ | ||
'bTableExists' => $bTableExists, | ||
'sVendor' => 'oneplace', | ||
'sModule' => 'oneplace-article-history', | ||
]); | ||
} else { | ||
$sSetupConfig = $oRequest->getPost('plc_module_setup_config'); | ||
|
||
$sSetupFile = 'vendor/oneplace/oneplace-article-history/data/install.sql'; | ||
if(file_exists($sSetupFile)) { | ||
echo 'got install file..'; | ||
$this->parseSQLInstallFile($sSetupFile,CoreUpdateController::$oDbAdapter); | ||
} | ||
|
||
if($sSetupConfig != '') { | ||
$sConfigStruct = 'vendor/oneplace/oneplace-article-history/data/structure_'.$sSetupConfig.'.sql'; | ||
if(file_exists($sConfigStruct)) { | ||
echo 'got struct file for config '.$sSetupConfig; | ||
$this->parseSQLInstallFile($sConfigStruct,CoreUpdateController::$oDbAdapter); | ||
} | ||
$sConfigData = 'vendor/oneplace/oneplace-article-history/data/data_'.$sSetupConfig.'.sql'; | ||
if(file_exists($sConfigData)) { | ||
echo 'got data file for config '.$sSetupConfig; | ||
$this->parseSQLInstallFile($sConfigData,CoreUpdateController::$oDbAdapter); | ||
} | ||
} | ||
|
||
$oModTbl = new TableGateway('core_module', CoreUpdateController::$oDbAdapter); | ||
$oModTbl->insert([ | ||
'module_key' => 'oneplace-article-history', | ||
'type' => 'plugin', | ||
'version' => \OnePlace\Article\History\Module::VERSION, | ||
'label' => 'onePlace Article History', | ||
'vendor' => 'oneplace', | ||
]); | ||
|
||
try { | ||
$this->oTableGateway->fetchAll(false); | ||
$bTableExists = true; | ||
} catch (\RuntimeException $e) { | ||
|
||
} | ||
$bTableExists = false; | ||
|
||
$this->flashMessenger()->addSuccessMessage('Article History DB Update successful'); | ||
$this->redirect()->toRoute('application', ['action' => 'checkforupdates']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<h2>Check for installation</h2> | ||
</div> | ||
<div class="card-body"> | ||
<form action="" method="POST"> | ||
<div class="form-group"> | ||
<?php | ||
?> | ||
<?php | ||
if($bTableExists) { ?> | ||
<div class="alert alert-success py-2 px-2"> | ||
<?=$this->translate('Database is up-to-date')?> | ||
</div> | ||
<?php | ||
} else { ?> | ||
<div class="alert alert-warning py-2 px-2"> | ||
<?=$this->translate('Database needs update. Please choose config')?> | ||
</div> | ||
<?php | ||
if(file_exists('vendor/'.$sVendor.'/'.$sModule.'/data/structure_simple.sql')) { | ||
?> <br/><input type="radio" name="plc_module_setup_config" value="simple" checked /> Simple | ||
<?php | ||
} | ||
if(file_exists('vendor/'.$sVendor.'/'.$sModule.'/data/structure_extended.sql')) { | ||
?> <br/><input type="radio" name="plc_module_setup_config" value="extended" /> Simple | ||
<?php | ||
} | ||
} | ||
?> | ||
</div> | ||
|
||
<?php if (! $bTableExists) { ?> | ||
<div class="form-group"> | ||
<button type="submit" class="btn btn-primary"> | ||
<?=$this->translate('Update Database')?> | ||
</button> | ||
</div> | ||
<?php } ?> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |