├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── config ├── config.yml ├── index.php ├── pre-commit └── services.yml ├── controllers ├── admin │ ├── AdminSkeletonInfoController.php │ ├── AdminSkeletonTabController.php │ └── index.php └── index.php ├── index.php ├── skeleton.php ├── src ├── Controller │ ├── AdminController.php │ └── index.php ├── Install │ ├── AbstractInstaller.php │ ├── Installer.php │ ├── Tab.php │ ├── Uninstaller.php │ └── index.php └── index.php └── var ├── cache └── index.php └── index.php /.gitignore: -------------------------------------------------------------------------------- 1 | *.xml 2 | .idea/ 3 | var/cache/container.php 4 | var/cache/container.php.meta 5 | var/logs/* 6 | /vendor -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | 9 | ## [1.0.0] - YYYY-MM-DD 10 | ### Added 11 | - Something added. 12 | 13 | ### Changed 14 | - Something changed. 15 | 16 | ### Removed 17 | - Something removed. 18 | 19 | ### Fixed 20 | - Something fixed. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Invertus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PrestaShop module skeleton 2 | 3 | PrestaShop module skeleton used for version >= 1.7.1 4 | 5 | ## Getting Started 6 | 7 | clone repository and add it to modules folder on a PrestaShop system 8 | 9 | ### Prerequisites 10 | * composer 11 | * PHP >= 5.4 12 | 13 | ### Installing 14 | 15 | 1. Change both module folder and main class name to your module name. 16 | 2. Find and replace on module scope all texts which starts with *Skeleton* or *skeleton* string to your module name. 17 | 3. Execute *composer install*. 18 | 4. If module does not appear in the list, make sure name in the constructor matches the main file and folder name and also if folders have right permissions. 19 | 5. Install module. 20 | 21 | ## License 22 | 23 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details 24 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "invertus/skeleton", 3 | "type": "prestashop-module", 4 | "authors": [ 5 | { 6 | "name": "Invertus", 7 | "email": "help@invertus.eu" 8 | } 9 | ], 10 | "autoload": { 11 | "psr-4": { 12 | "Invertus\\Skeleton\\": "src/" 13 | } 14 | }, 15 | "require": { 16 | "php": ">=5.4" 17 | }, 18 | "require-dev": { 19 | "squizlabs/php_codesniffer": "^3.2" 20 | }, 21 | "scripts": { 22 | "post-install-cmd": [ 23 | "php -r \"copy('config/pre-commit', '.git/hooks/pre-commit');\"" 24 | ], 25 | "post-update-cmd": [ 26 | "php -r \"copy('config/pre-commit', '.git/hooks/pre-commit');\"" 27 | ] 28 | } 29 | } -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "a973ad05762941203b1cbc74739a1c8d", 8 | "packages": [], 9 | "packages-dev": [ 10 | { 11 | "name": "squizlabs/php_codesniffer", 12 | "version": "3.2.3", 13 | "source": { 14 | "type": "git", 15 | "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", 16 | "reference": "4842476c434e375f9d3182ff7b89059583aa8b27" 17 | }, 18 | "dist": { 19 | "type": "zip", 20 | "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4842476c434e375f9d3182ff7b89059583aa8b27", 21 | "reference": "4842476c434e375f9d3182ff7b89059583aa8b27", 22 | "shasum": "" 23 | }, 24 | "require": { 25 | "ext-simplexml": "*", 26 | "ext-tokenizer": "*", 27 | "ext-xmlwriter": "*", 28 | "php": ">=5.4.0" 29 | }, 30 | "require-dev": { 31 | "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" 32 | }, 33 | "bin": [ 34 | "bin/phpcs", 35 | "bin/phpcbf" 36 | ], 37 | "type": "library", 38 | "extra": { 39 | "branch-alias": { 40 | "dev-master": "3.x-dev" 41 | } 42 | }, 43 | "notification-url": "https://packagist.org/downloads/", 44 | "license": [ 45 | "BSD-3-Clause" 46 | ], 47 | "authors": [ 48 | { 49 | "name": "Greg Sherwood", 50 | "role": "lead" 51 | } 52 | ], 53 | "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", 54 | "homepage": "http://www.squizlabs.com/php-codesniffer", 55 | "keywords": [ 56 | "phpcs", 57 | "standards" 58 | ], 59 | "time": "2018-02-20T21:35:23+00:00" 60 | } 61 | ], 62 | "aliases": [], 63 | "minimum-stability": "stable", 64 | "stability-flags": [], 65 | "prefer-stable": false, 66 | "prefer-lowest": false, 67 | "platform": { 68 | "php": ">=5.4" 69 | }, 70 | "platform-dev": [] 71 | } 72 | -------------------------------------------------------------------------------- /config/config.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: 'services.yml' } 3 | 4 | parameters: 5 | module_settings: 6 | configuration: 7 | 8 | hooks: 9 | - 'actionDispatcherBefore' 10 | 11 | tabs: 12 | - {name: 'Skeleton', parent_class_name: 'AdminParentModulesSf', class_name: 'AdminSkeletonTab', visible: false} 13 | - {name: 'Info', parent_class_name: 'AdminSkeletonTab', class_name: 'AdminSkeletonInfo'} -------------------------------------------------------------------------------- /config/index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license Addons PrestaShop license limitation 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | -------------------------------------------------------------------------------- /config/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"` 4 | STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php` 5 | 6 | # Determine if a file list is passed 7 | if [ "$#" -eq 1 ] 8 | then 9 | oIFS=$IFS 10 | IFS=' 11 | ' 12 | SFILES="$1" 13 | IFS=$oIFS 14 | fi 15 | SFILES=${SFILES:-$STAGED_FILES_CMD} 16 | 17 | echo "Checking PHP Lint..." 18 | for FILE in $SFILES 19 | do 20 | php -l -d display_errors=0 $PROJECT/$FILE 21 | if [ $? != 0 ] 22 | then 23 | echo "Fix the error before commit." 24 | exit 1 25 | fi 26 | FILES="$FILES $PROJECT/$FILE" 27 | done 28 | 29 | if [ "$FILES" != "" ] 30 | then 31 | echo "Running Code Sniffer..." 32 | vendor/squizlabs/php_codesniffer/bin/phpcs --standard=PSR1,PSR2 --ignore=tests/,src/Entity,controllers/,skeleton.php $FILES 33 | if [ $? != 0 ] 34 | then 35 | echo "Fix the error before commit." 36 | exit 1 37 | fi 38 | fi 39 | 40 | exit $? -------------------------------------------------------------------------------- /config/services.yml: -------------------------------------------------------------------------------- 1 | services: 2 | skeleton.module: 3 | class: 'Skeleton' 4 | factory: ['Module', 'getInstanceByName'] 5 | arguments: 6 | - 'skeleton' 7 | 8 | # Installers 9 | install.tab: 10 | class: 'Invertus\Skeleton\Install\Tab' 11 | arguments: 12 | - '%module_settings%' 13 | 14 | installer: 15 | class: 'Invertus\Skeleton\Install\Installer' 16 | arguments: 17 | - '@skeleton.module' 18 | - '%module_settings%' 19 | 20 | uninstaller: 21 | class: 'Invertus\Skeleton\Install\Uninstaller' 22 | arguments: 23 | - '@skeleton.module' 24 | - '%module_settings%' -------------------------------------------------------------------------------- /controllers/admin/AdminSkeletonInfoController.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | /** 14 | * Class AdminSkeletonInfoController - used for information display for module 15 | */ 16 | class AdminSkeletonInfoController extends \Invertus\Skeleton\Controller\AdminController 17 | { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /controllers/admin/AdminSkeletonTabController.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | /** 14 | * Class AdminSkeletonTabController - it is invisible tab used for other tab display inheritance 15 | */ 16 | class AdminSkeletonTabController extends \Invertus\Skeleton\Controller\AdminController 17 | { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /controllers/admin/index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license Addons PrestaShop license limitation 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | -------------------------------------------------------------------------------- /controllers/index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license Addons PrestaShop license limitation 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | -------------------------------------------------------------------------------- /skeleton.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | use Invertus\Skeleton\Install\Installer; 14 | use Invertus\Skeleton\Install\Uninstaller; 15 | use Symfony\Component\Config\ConfigCache; 16 | use Symfony\Component\DependencyInjection\ContainerBuilder; 17 | use Symfony\Component\DependencyInjection\Dumper\PhpDumper; 18 | use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; 19 | use Symfony\Component\Config\FileLocator; 20 | use \Invertus\Skeleton\Install\Tab; 21 | 22 | class Skeleton extends Module 23 | { 24 | /** 25 | * If false, then SkeletonContainer is in immutable state 26 | */ 27 | const DISABLE_CACHE = true; 28 | 29 | /** 30 | * @var SkeletonContainer 31 | */ 32 | private $moduleContainer; 33 | 34 | public function __construct() 35 | { 36 | $this->tab = 'other_modules'; 37 | $this->name = 'skeleton'; 38 | $this->version = '1.0.0'; 39 | $this->author = 'Invertus'; 40 | 41 | parent::__construct(); 42 | $this->autoLoad(); 43 | $this->compile(); 44 | $this->displayName = $this->l('Skeleton'); 45 | $this->description = $this->l('This is module description'); 46 | } 47 | 48 | public function getTabs() 49 | { 50 | /** @var Tab $tab */ 51 | $tab = $this->getContainer()->get('install.tab'); 52 | return $tab->getTabs(); 53 | } 54 | 55 | public function getContent() 56 | { 57 | /** @var Tab $tab */ 58 | $tab = $this->getContainer()->get('install.tab'); 59 | 60 | $redirectLink = $this->context->link->getAdminLink($tab->getControllerInfo()); 61 | Tools::redirectAdmin($redirectLink); 62 | } 63 | 64 | public function install() 65 | { 66 | /** @var Installer $installer */ 67 | $installer = $this->getContainer()->get('installer'); 68 | 69 | return parent::install() && $installer->init(); 70 | } 71 | 72 | public function uninstall() 73 | { 74 | /** @var Uninstaller $unInstaller */ 75 | $unInstaller = $this->getContainer()->get('uninstaller'); 76 | 77 | return parent::uninstall() && $unInstaller->init(); 78 | } 79 | 80 | public function hookActionDispatcherBefore() 81 | { 82 | $this->autoLoad(); 83 | } 84 | 85 | /** 86 | * Gets container with loaded classes defined in src folder 87 | * 88 | * @return SkeletonContainer 89 | */ 90 | public function getContainer() 91 | { 92 | return $this->moduleContainer; 93 | } 94 | 95 | /** 96 | * Autoload's project files from /src directory 97 | */ 98 | private function autoLoad() 99 | { 100 | $autoLoadPath = $this->getLocalPath().'vendor/autoload.php'; 101 | 102 | require_once $autoLoadPath; 103 | } 104 | 105 | /** 106 | * Creates compiled dependency injection container which holds data configured in config/config.yml file. 107 | * 108 | * @throws Exception 109 | */ 110 | private function compile() 111 | { 112 | $containerCache = $this->getLocalPath().'var/cache/container.php'; 113 | $containerConfigCache = new ConfigCache($containerCache, self::DISABLE_CACHE); 114 | 115 | $containerClass = get_class($this).'Container'; 116 | 117 | if (!$containerConfigCache->isFresh()) { 118 | $containerBuilder = new ContainerBuilder(); 119 | $locator = new FileLocator($this->getLocalPath().'/config'); 120 | $loader = new YamlFileLoader($containerBuilder, $locator); 121 | $loader->load('config.yml'); 122 | $containerBuilder->compile(); 123 | $dumper = new PhpDumper($containerBuilder); 124 | 125 | $containerConfigCache->write( 126 | $dumper->dump(['class' => $containerClass]), 127 | $containerBuilder->getResources() 128 | ); 129 | } 130 | 131 | require_once $containerCache; 132 | $this->moduleContainer = new $containerClass(); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/Controller/AdminController.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | namespace Invertus\Skeleton\Controller; 14 | 15 | /** 16 | * Class AdminController - an abstraction for all admin controllers 17 | */ 18 | class AdminController extends \ModuleAdminController 19 | { 20 | public function __construct() 21 | { 22 | parent::__construct(); 23 | $this->bootstrap = true; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Controller/index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license Addons PrestaShop license limitation 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | -------------------------------------------------------------------------------- /src/Install/AbstractInstaller.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | namespace Invertus\Skeleton\Install; 14 | 15 | use Db; 16 | use Exception; 17 | 18 | abstract class AbstractInstaller 19 | { 20 | /** 21 | * @return bool 22 | */ 23 | abstract public function init(); 24 | 25 | /** 26 | * used to parse sql files, replace variables and prepare for execution 27 | * 28 | * @param string $fileName 29 | * @return string 30 | */ 31 | abstract protected function getSqlStatements($fileName); 32 | 33 | /** 34 | * Gets current file name. Used for translations 35 | * 36 | * @param string $classInstance 37 | * 38 | * @return string 39 | * 40 | * @throws \ReflectionException 41 | */ 42 | protected function getFileName($classInstance) 43 | { 44 | $reflection = new \ReflectionClass($classInstance); 45 | return $reflection->getShortName(); 46 | } 47 | 48 | /** 49 | * Executes sql statements 50 | * 51 | * @param Db $database 52 | * @param string $sqlStatements 53 | * 54 | * @return bool 55 | * @throws Exception 56 | */ 57 | protected function execute(Db $database, $sqlStatements) 58 | { 59 | try { 60 | $result = $database->execute($sqlStatements); 61 | } catch (Exception $e) { 62 | throw new Exception($e->getMessage()); 63 | } 64 | 65 | return $result; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Install/Installer.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | namespace Invertus\Skeleton\Install; 14 | 15 | use Configuration; 16 | use Db; 17 | use Exception; 18 | use Tools; 19 | 20 | /** 21 | * Class Installer - responsible for module installation process 22 | */ 23 | class Installer extends AbstractInstaller 24 | { 25 | /** 26 | * @var \Skeleton 27 | */ 28 | private $module; 29 | /** 30 | * @var array 31 | */ 32 | private $configuration; 33 | 34 | /** 35 | * @param \Skeleton $module 36 | * @param array $configuration 37 | */ 38 | public function __construct(\Skeleton $module, array $configuration) 39 | { 40 | $this->module = $module; 41 | $this->configuration = $configuration; 42 | } 43 | 44 | /** 45 | * {@inheritdoc} 46 | */ 47 | public function init() 48 | { 49 | if (!$this->registerHooks()) { 50 | return false; 51 | } 52 | 53 | if (!$this->installConfiguration()) { 54 | return false; 55 | } 56 | 57 | if (!$this->installDb()) { 58 | return false; 59 | } 60 | 61 | return true; 62 | } 63 | 64 | /** 65 | * {@inheritdoc} 66 | */ 67 | protected function getSqlStatements($fileName) 68 | { 69 | $sqlStatements = Tools::file_get_contents($fileName); 70 | $sqlStatements = str_replace(['PREFIX_', 'ENGINE_TYPE'], [_DB_PREFIX_, _MYSQL_ENGINE_], $sqlStatements); 71 | 72 | return $sqlStatements; 73 | } 74 | 75 | /** 76 | * @return bool 77 | * 78 | * @throws \Exception 79 | */ 80 | private function registerHooks() 81 | { 82 | $hooks = $this->configuration['hooks']; 83 | 84 | if (empty($hooks)) { 85 | return true; 86 | } 87 | 88 | foreach ($hooks as $hookName) { 89 | if (!$this->module->registerHook($hookName)) { 90 | throw new Exception( 91 | sprintf( 92 | $this->module->l('Hook %s has not been installed.', $this->getFileName($this)), 93 | $hookName 94 | ) 95 | ); 96 | } 97 | } 98 | 99 | return true; 100 | } 101 | 102 | /** 103 | * Installs global settings 104 | * 105 | * @return bool 106 | * 107 | * @throws \Exception 108 | */ 109 | private function installConfiguration() 110 | { 111 | $configuration = $this->configuration['configuration']; 112 | 113 | if (empty($configuration)) { 114 | return true; 115 | } 116 | 117 | foreach ($configuration as $name => $value) { 118 | if (!Configuration::updateValue($name, $value)) { 119 | throw new Exception( 120 | sprintf( 121 | $this->module->l('Configuration %s has not been installed.', $this->getFileName($this)), 122 | $name 123 | ) 124 | ); 125 | } 126 | } 127 | 128 | return true; 129 | } 130 | 131 | /** 132 | * Reads sql files and executes 133 | * 134 | * @return bool 135 | * @throws Exception 136 | */ 137 | private function installDb() 138 | { 139 | $installSqlFiles = glob($this->module->getLocalPath().'sql/install/*.sql'); 140 | 141 | if (empty($installSqlFiles)) { 142 | return true; 143 | } 144 | 145 | $database = Db::getInstance(); 146 | 147 | foreach ($installSqlFiles as $sqlFile) { 148 | $sqlStatements = $this->getSqlStatements($sqlFile); 149 | 150 | try { 151 | $this->execute($database, $sqlStatements); 152 | } catch (Exception $exception) { 153 | throw new Exception($exception->getMessage()); 154 | } 155 | } 156 | 157 | return true; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/Install/Tab.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | namespace Invertus\Skeleton\Install; 14 | 15 | /** 16 | * Class Tab - module admin tab settings 17 | */ 18 | class Tab 19 | { 20 | /** 21 | * @var string info controller name 22 | */ 23 | private $controllerInfo = 'AdminSkeletonInfo'; 24 | 25 | /** 26 | * @var array 27 | */ 28 | private $configuration; 29 | 30 | /** 31 | * @param array $configuration 32 | */ 33 | public function __construct(array $configuration) 34 | { 35 | $this->configuration = $configuration; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getControllerInfo() 42 | { 43 | return $this->controllerInfo; 44 | } 45 | 46 | /** 47 | * @return array 48 | */ 49 | public function getTabs() 50 | { 51 | return isset($this->configuration['tabs']) ? $this->configuration['tabs'] : []; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Install/Uninstaller.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license MIT 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | namespace Invertus\Skeleton\Install; 14 | 15 | use Configuration; 16 | use Tools; 17 | 18 | /** 19 | * Class Uninstaller - responsible for module installation process 20 | */ 21 | class Uninstaller extends AbstractInstaller 22 | { 23 | /** 24 | * @var \Skeleton 25 | */ 26 | private $module; 27 | /** 28 | * @var array 29 | */ 30 | private $configuration; 31 | 32 | /** 33 | * @param \Skeleton $module 34 | * @param array $configuration 35 | */ 36 | public function __construct(\Skeleton $module, array $configuration) 37 | { 38 | $this->module = $module; 39 | $this->configuration = $configuration; 40 | } 41 | 42 | /** 43 | * {@inheritdoc} 44 | */ 45 | public function init() 46 | { 47 | $this->uninstallConfiguration(); 48 | 49 | if (!$this->uninstallDb()) { 50 | return false; 51 | } 52 | return true; 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | */ 58 | protected function getSqlStatements($fileName) 59 | { 60 | $sqlStatements = Tools::file_get_contents($fileName); 61 | $sqlStatements = str_replace(['PREFIX_', 'ENGINE_TYPE'], [_DB_PREFIX_, _MYSQL_ENGINE_], $sqlStatements); 62 | 63 | return $sqlStatements; 64 | } 65 | 66 | private function uninstallConfiguration() 67 | { 68 | $configuration = $this->configuration['configuration']; 69 | 70 | if (empty($configuration)) { 71 | return; 72 | } 73 | 74 | foreach (array_keys($configuration) as $name) { 75 | if (!Configuration::deleteByName($name)) { 76 | continue; 77 | } 78 | } 79 | } 80 | 81 | /** 82 | * Executes sql in uninstall.sql file which is used for uninstalling 83 | * 84 | * @return bool 85 | * 86 | * @throws \Exception 87 | */ 88 | private function uninstallDb() 89 | { 90 | $uninstallSqlFileName = $this->module->getLocalPath().'sql/uninstall/uninstall.sql'; 91 | if (!file_exists($uninstallSqlFileName)) { 92 | return true; 93 | } 94 | 95 | $database = \Db::getInstance(); 96 | $sqlStatements = $this->getSqlStatements($uninstallSqlFileName); 97 | return (bool) $this->execute($database, $sqlStatements); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Install/index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license Addons PrestaShop license limitation 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | -------------------------------------------------------------------------------- /src/index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license Addons PrestaShop license limitation 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | -------------------------------------------------------------------------------- /var/cache/index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license Addons PrestaShop license limitation 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | -------------------------------------------------------------------------------- /var/index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) permanent, INVERTUS, UAB 7 | * @license Addons PrestaShop license limitation 8 | * @see /LICENSE 9 | * 10 | * International Registered Trademark & Property of INVERTUS, UAB 11 | */ 12 | 13 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 14 | header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); 15 | 16 | header("Cache-Control: no-store, no-cache, must-revalidate"); 17 | header("Cache-Control: post-check=0, pre-check=0", false); 18 | header("Pragma: no-cache"); 19 | 20 | header("Location: ../"); 21 | exit; 22 | --------------------------------------------------------------------------------