Skip to content

Commit

Permalink
setup improved
Browse files Browse the repository at this point in the history
  • Loading branch information
Praesidiarius committed Feb 11, 2020
1 parent 2046d2d commit 94de45e
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 16 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "oneplace/oneplace-core",
"description": "onePlace Core Application",
"type": "project",
"version": "1.0.18",
"version": "1.0.19",
"license": "BSD-3-Clause",
"keywords": [
"laminas",
Expand Down Expand Up @@ -31,7 +31,7 @@
"laminas/laminas-session": "^2.9.1",
"laminas/laminas-paginator": "^2.8",
"laminas/laminas-mail": "^2.10",
"oneplace/oneplace-user": "^1.0.0"
"oneplace/oneplace-user": "^1.0.12"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion module/Application/data/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ INSERT INTO `permission` (`permission_key`, `module`, `label`, `nav_label`, `nav
('updateuppysort', 'Application\\Controller\\UploadController', 'Gallery Upload', '', '', 0),
('quicksearch', 'Application\\Controller\\IndexController', 'Quick Search', '', '', 0),
('updatefieldsort', 'Application\\Controller\\IndexController', 'Update Form Field Sorting', '', '', 0),
('selectbool', 'Application\\Controller\\IndexController', 'Select Yes/No', '', '', 0);
('selectbool', 'Application\\Controller\\IndexController', 'Select Yes/No', '', '', 0),
('checkforupdates', 'Application\\Controller\\IndexController', 'Check for Updates', '', '', 0);

--
-- Default Widgets
Expand Down
11 changes: 11 additions & 0 deletions module/Application/data/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ ALTER TABLE `core_gallery_media`
ALTER TABLE `core_gallery_media`
MODIFY `Media_ID` int(11) NOT NULL AUTO_INCREMENT;

CREATE TABLE `core_module` (
`module_key` varchar(255) NOT NULL,
`version` varchar(10) NOT NULL,
`label` varchar(255) NOT NULL,
`type` varchar(50) NOT NULL,
`vendor` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `core_module`
ADD PRIMARY KEY (`module_key`);

--
-- Save
--
Expand Down
61 changes: 61 additions & 0 deletions module/Application/src/Controller/CoreUpdateController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* CoreUpdateController.php - Update DB Controller
*
* Main Controller DB Update for all modules
*
* @category Controller
* @package Application
* @author Verein onePlace
* @copyright (C) 2020 Verein onePlace <[email protected]>
* @license https://opensource.org/licenses/BSD-3-Clause
* @version 1.0.0
* @since 1.0.0
*/

declare(strict_types=1);

namespace Application\Controller;
use Laminas\Db\Adapter\AdapterInterface;
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
use Laminas\View\Model\ViewModel;
use Laminas\Db\Sql\Select;
use Zend\I18n\Translator\Translator;

class CoreUpdateController extends CoreController {
/**
* Article Table Object
*
* @since 1.0.0
*/
protected $oTableGateway;

public function __construct(AdapterInterface $oDbAdapter,$oTableGateway = false,$oServiceManager) {
parent::__construct($oDbAdapter,$oTableGateway,$oServiceManager);
}

/**
* Parse SQL File from Installer and save to database
*
* @param string $sFile location of sql file
* @param AdapterInterface $oAdapter database connection
* @since 1.0.2.1
*/
protected function parseSQLInstallFile($sFile,$oAdapter) {
$templine = '';
$lines = file($sFile);
// Loop through each line
foreach ($lines as $line) {
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
$results = $oAdapter->query($templine, $oAdapter::QUERY_MODE_EXECUTE);
$templine = '';
}
}
}
}
51 changes: 39 additions & 12 deletions module/Application/src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public function indexAction() {
$this->layout('layout/layout-'.CoreController::$oSession->oUser->getTheme());

$aMeasureEnd = getrusage();
$this->logPerfomance('application-index',$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"utime"),$this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"stime"));
$sRuTime = $this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"utime");
$sRsTime = $this->rutime($aMeasureEnd,CoreController::$aPerfomanceLogStart,"stime");
$this->logPerfomance('application-index',$sRuTime,$sRsTime);

return new ViewModel([
'oUser'=>CoreController::$oSession->oUser,
Expand Down Expand Up @@ -63,7 +65,9 @@ public function updateAction() {
'update' => [],
];

foreach(glob($_SERVER['DOCUMENT_ROOT'].'/../vendor/oneplace/*', GLOB_ONLYDIR) as $sModulePath) {
$sPath = $_SERVER['DOCUMENT_ROOT'].'/../vendor/oneplace/*';

foreach(glob($sPath, GLOB_ONLYDIR) as $sModulePath) {
$sModule = basename($sModulePath);
$sModuleName = explode('-',$sModule)[1];

Expand All @@ -77,10 +81,12 @@ public function updateAction() {
}

try {
$oBaseTbl = new TableGateway($sModuleName,CoreController::$oDbAdapter);
$oBaseTbl = new TableGateway($sModuleName, CoreController::$oDbAdapter);
$oBaseTbl->select();

foreach(glob($_SERVER['DOCUMENT_ROOT'].'/../vendor/oneplace/oneplace-'.$sModuleName.'-*', GLOB_ONLYDIR) as $sPluginName) {
$sTagPath = $_SERVER['DOCUMENT_ROOT'].'/../vendor/oneplace/oneplace-'.$sModuleName.'-*';

foreach(glob($sTagPath, GLOB_ONLYDIR) as $sPluginName) {
$sPluginTbl = str_replace(['-'],['_'],substr(basename($sPluginName),strlen('oneplace-')));
echo $sPluginTbl;
if(file_exists($sPluginName.'/data/install.sql')) {
Expand Down Expand Up @@ -466,14 +472,15 @@ public function quicksearchAction() {
];
}

public function updatefieldsortAction() {
public function updatefieldsortAction()
{
$this->setThemeBasedLayout('application');

$oRequest = $this->getRequest();

if(!$oRequest->isPost()) {
$sFormKey = $this->params()->fromRoute('formname','none');
$oForm = CoreController::$aCoreTables['core-form']->select(['form_key'=>$sFormKey]);
$oForm = CoreController::$aCoreTables['core-form']->select(['form_key' => $sFormKey]);

if(count($oForm) == 0) {
echo 'form not found';
Expand All @@ -484,8 +491,8 @@ public function updatefieldsortAction() {

# Add Links for Breadcrumb
$this->layout()->aNavLinks = [
(object)['label'=>'Form Field Sorting'],
(object)['label'=>$oForm->label],
(object)['label' => 'Form Field Sorting'],
(object)['label' => $oForm->label],
];

# Add Buttons for breadcrumb
Expand Down Expand Up @@ -515,8 +522,8 @@ public function updatefieldsortAction() {
}

return new ViewModel([
'oForm'=>$oForm,
'aFieldsByTabs'=>$aFieldsByTabs,
'oForm' => $oForm,
'aFieldsByTabs' => $aFieldsByTabs,
]);
} else {
$this->layout('layout/json');
Expand All @@ -538,15 +545,16 @@ public function updatefieldsortAction() {
}
}

$aReturn = ['state'=>'success','message'=>'order updated'];
$aReturn = ['state' => 'success','message' => 'order updated'];

echo json_encode($aReturn);

return false;
}
}

public function selectboolAction() {
public function selectboolAction()
{
$this->layout('layout/json');

$aResults = [];
Expand All @@ -557,4 +565,23 @@ public function selectboolAction() {
'aResults'=>$aResults,
]);
}

public function checkforupdatesAction()
{
$this->setThemeBasedLayout('application');

$oModuleTbl = new TableGateway('core_module',CoreController::$oDbAdapter);
$aModulesInstalled = [];
$oModulesDB = $oModuleTbl->select();
if(count($oModulesDB) > 0) {
foreach($oModulesDB as $oMod) {
$aModulesInstalled[$oMod->module_key] = $oMod;
}
}


return new ViewModel([
'aModulesInstalled' => $aModulesInstalled
]);
}
}
17 changes: 17 additions & 0 deletions module/Application/src/Controller/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,23 @@ public function indexAction() {
$iFieldSortID++;
}

# Add core modules
$oCoreModules = new TableGateway('core_module',$adapter);
$oCoreModules->insert([
'module_key'=>'oneplace-core',
'version'=> \Application\Module::VERSION,
'label'=>'onePlace Core',
'type'=>'module',
'vendor'=>'oneplace',
]);
$oCoreModules->insert([
'module_key'=>'oneplace-user',
'version'=> \OnePlace\User\Module::VERSION,
'label'=>'onePlace User',
'type'=>'module',
'vendor'=>'oneplace',
]);

return $this->redirect()->toRoute('login');
}
}
Expand Down
2 changes: 1 addition & 1 deletion module/Application/src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Module {
*
* @since 1.0.0
*/
const VERSION = '1.0.18';
const VERSION = '1.0.19';

public function getConfig() : array {
return include __DIR__ . '/../config/module.config.php';
Expand Down
66 changes: 66 additions & 0 deletions module/Application/view/application/index/checkforupdates.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
?>
<h2>Installed Modules</h2>
<ul class="list-group">
<?php
foreach($aModulesInstalled as $oMod) {
$sPath = 'vendor/'.$oMod->vendor.'/'.$oMod->module_key.'/src/Module.php';
if($oMod->module_key == 'oneplace-core') {
$sPath = 'module/Application/src/Module.php';
}
if(file_exists($sPath)) {
$sModule = str_replace(['-'],['\\'],$oMod->module_key);
$sClass = "$sModule\\Module";
$sInstalledVer = '(unknown)';
if($oMod->module_key == 'oneplace-core') {
$sClass = "Application\\Module";
}
$sInstalledVer = $sClass::VERSION;
?>
<li class="list-group-item">
<?=$oMod->label?> - <?=$oMod->version?> - <?=$sClass::VERSION?>
</li>
<?php
}
?>
<?php
}
?>
<h2>New Modules to install</h2>
<ul class="list-group">
<?php
$aVendors = ['oneplace'];
foreach($aVendors as $sVendor) {
$aModules = glob('vendor/'.$sVendor.'/*', GLOB_ONLYDIR);
foreach($aModules as $sMod) {
$sModName = basename($sMod);
if(!array_key_exists($sModName,$aModulesInstalled)) {
$sPath = 'vendor/'.$sVendor.'/'.$sModName.'/src/Module.php';
if(file_exists($sPath)) {
require_once $sPath;
$sClass = ucfirst($sVendor)."\\".ucfirst(explode('-',$sModName)[1])."\\Module";
$sModVer = $sClass::VERSION;

$sUrl = '';
try {
$sModRoute = explode('-',$sModName)[1];
$sUrl = $this->url($sModRoute.'-setup');
} catch(\RuntimeException $e) {

}
?>
<li class="list-group-item">
<?=$sModName?> - <?=$sModVer?>
<?php if($sUrl != '') { ?>
- <a href="<?=$sUrl?>" title="Run Setup">
Run setup
</a>
<?php } ?>
</li>
<?php
}
}
}
}
?>
</ul>

0 comments on commit 94de45e

Please sign in to comment.