diff --git a/composer.json b/composer.json index dc5b5a6..8879192 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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": { diff --git a/module/Application/data/data.sql b/module/Application/data/data.sql index 4d3b1a5..0e0c473 100644 --- a/module/Application/data/data.sql +++ b/module/Application/data/data.sql @@ -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 diff --git a/module/Application/data/structure.sql b/module/Application/data/structure.sql index 268bd81..1392f92 100644 --- a/module/Application/data/structure.sql +++ b/module/Application/data/structure.sql @@ -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 -- diff --git a/module/Application/src/Controller/CoreUpdateController.php b/module/Application/src/Controller/CoreUpdateController.php new file mode 100644 index 0000000..a1c8df6 --- /dev/null +++ b/module/Application/src/Controller/CoreUpdateController.php @@ -0,0 +1,61 @@ + + * @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 = ''; + } + } + } +} diff --git a/module/Application/src/Controller/IndexController.php b/module/Application/src/Controller/IndexController.php index 9829506..cd0369f 100644 --- a/module/Application/src/Controller/IndexController.php +++ b/module/Application/src/Controller/IndexController.php @@ -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, @@ -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]; @@ -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')) { @@ -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'; @@ -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 @@ -515,8 +522,8 @@ public function updatefieldsortAction() { } return new ViewModel([ - 'oForm'=>$oForm, - 'aFieldsByTabs'=>$aFieldsByTabs, + 'oForm' => $oForm, + 'aFieldsByTabs' => $aFieldsByTabs, ]); } else { $this->layout('layout/json'); @@ -538,7 +545,7 @@ public function updatefieldsortAction() { } } - $aReturn = ['state'=>'success','message'=>'order updated']; + $aReturn = ['state' => 'success','message' => 'order updated']; echo json_encode($aReturn); @@ -546,7 +553,8 @@ public function updatefieldsortAction() { } } - public function selectboolAction() { + public function selectboolAction() + { $this->layout('layout/json'); $aResults = []; @@ -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 + ]); + } } diff --git a/module/Application/src/Controller/SetupController.php b/module/Application/src/Controller/SetupController.php index 8e51ba8..4d6bafb 100644 --- a/module/Application/src/Controller/SetupController.php +++ b/module/Application/src/Controller/SetupController.php @@ -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'); } } diff --git a/module/Application/src/Module.php b/module/Application/src/Module.php index 74b209e..13db302 100644 --- a/module/Application/src/Module.php +++ b/module/Application/src/Module.php @@ -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'; diff --git a/module/Application/view/application/index/checkforupdates.phtml b/module/Application/view/application/index/checkforupdates.phtml new file mode 100644 index 0000000..44368e4 --- /dev/null +++ b/module/Application/view/application/index/checkforupdates.phtml @@ -0,0 +1,66 @@ + +