Skip to content

Commit

Permalink
add install checker (#3023)
Browse files Browse the repository at this point in the history
Add Symfony Installer's requirements check to our own installation and upgrade processes. Update and improve install and upgrade docs. Eliminate the use of system constants to indicate currently installed version and replace with permanently written parameter.
  • Loading branch information
craigh committed Aug 24, 2016
1 parent d45e42f commit 1a6f21a
Show file tree
Hide file tree
Showing 22 changed files with 236 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/composer.phar
/bin/
/src/app/bootstrap.php.cache
/src/app/SymfonyRequirements.php
/src/app/cache/
/src/app/config/custom_*.yml
/src/app/config/dynamic/*
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ install:
# drop the install test db
- mysql -e 'drop database zk_test'
# create an upgrade db for 1310
- 'sed -i -E "s/core_installed_version:(.*)/core_installed_version: ''1.3.10''/" app/config/custom_parameters.yml'
- mysql -e 'create database zk_test;'
- mysql zk_test < ../test_dbs/core1310.sql
# run the upgrade from the 1310 db
Expand All @@ -47,6 +48,7 @@ install:
# drop the install test db
- mysql -e 'drop database zk_test'
# create an upgrade db for 140
- 'sed -i -E "s/core_installed_version:(.*)/core_installed_version: ''1.4.0''/" app/config/custom_parameters.yml'
- mysql -e 'create database zk_test;'
- mysql zk_test < ../test_dbs/core140.sql
# run the upgrade from the 140 db
Expand All @@ -55,6 +57,7 @@ install:
# drop the install test db
- mysql -e 'drop database zk_test'
# create an upgrade db for 141
- 'sed -i -E "s/core_installed_version:(.*)/core_installed_version: ''1.4.1''/" app/config/custom_parameters.yml'
- mysql -e 'create database zk_test;'
- mysql zk_test < ../test_dbs/core141.sql
# run the upgrade from the 141 db
Expand All @@ -63,6 +66,7 @@ install:
# drop the install test db
- mysql -e 'drop database zk_test'
# create an upgrade db for 142
- 'sed -i -E "s/core_installed_version:(.*)/core_installed_version: ''1.4.2''/" app/config/custom_parameters.yml'
- mysql -e 'create database zk_test;'
- mysql zk_test < ../test_dbs/core142.sql
# run the upgrade from the 142 db
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CHANGELOG - ZIKULA 1.4.x
- Corrected issue with hook admin url and legacy modules (#2999).
- Imagine: Use Imagick or Gmagick in favour of Gd (#3016)
- Add filter to LoginBlock so it doesn't appear on login page (#3021).
- Improved Installer and Upgrader to check installation requirements before running (#2235, #3023).

- Features:
- Add help text, alert text and input groups to forms utilizing the provided form themes (#2846, #2847).
Expand Down
45 changes: 26 additions & 19 deletions INSTALL-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Zikula Installation Instructions


<a name="zikula"></a>
1. Zikula

Zikula
---------

Zikula is an open source, open development application framework for dynamic
Expand All @@ -27,8 +28,9 @@ to open an issue at the GitHub Core Repository and we will try to fix any proble


<a name="requirements"></a>
2. Server Consideration
-----------------------

Server/Environment Requirements
-------------------------------

Before upgrading Zikula it's important to ensure that the hosting server environment meets the requirements
of the new core release. Zikula Core 1.4 has the following requirements:
Expand All @@ -51,8 +53,9 @@ of the new core release. Zikula Core 1.4 has the following requirements:


<a name="upload"></a>
3. Upload and Prepare
---------------------

Upload and Prepare
------------------

###Upload

Expand Down Expand Up @@ -88,8 +91,17 @@ the permission settings as they were set correctly by the development team, if y


<a name="install"></a>
4. New Installation
-------------------

New Installation
----------------

*Note 1:* One common issue when installing is that the app/cache and app/logs directories must be writable both by the
web server and the command line user. See Symfony's [Setting up or Fixing File Permissions](http://symfony.com/doc/2.8/setup/file_permissions.html)
to see potential solutions to this problem when installing from the CLI.

*Note 2:* If you have `mod_suexec` installed for Apache the CLI will run into permission problems. (If you are not sure
check your phpinfo.) `mod_suexec` often is used in shared hosting environments. In this case, the CLI installer is not
recommended, please use the Web Installer.

###Create the Database

Expand All @@ -98,21 +110,15 @@ Create a database on your server. Take note of the database **name** as well as
database, but this is not recommended unless Zikula will be the only application using that database. In this case,
remove all existing tables from the existing database.

###Web Installer
###Install by the Web installer or Command Line (not both!):

####Web Installer

To begin the installer, simply visit the root directory with your browser, e.g. `http://www.example.com/`.
If you installed Zikula into a subdirectory 'foo' the URL would be `http://www.example.com/foo/`. You will be
automatically redirected to the installer.

###Command Line Installer

*Note 1:* One common issue when installing is that the app/cache and app/logs directories must be writable both by the
web server and the command line user. See Symfony's [Setting up Permissions](http://symfony.com/doc/current/book/installation.html#book-installation-permissions)
to see potential solutions to this problem when installing from the CLI.

*Note 2:* If you have `mod_suexec` installed for Apache the CLI will run into permission problems. (If you are not sure
check your phpinfo.) `mod_suexec` often is used in shared hosting environments. In this case, the CLI installer is not
recommended, please use the Web Installer.
####Command Line Installer

Via CLI, access your main zikula directory (`/src` if a Github clone) and run this command:
```Shell
Expand All @@ -126,8 +132,9 @@ Open your browser and login!


<a name="final"></a>
5. Final Note
-------------

Final Note
----------

Modifications to the Zikula core system code or database are not supported. Doing so can cause extensive
problems when upgrading the system in the future and therefore these *hacks* are not recommended. Zikula
Expand Down
25 changes: 13 additions & 12 deletions UPGRADE-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ For more information visit http://zikula.org/ and read our

<a name="requirements"></a>

Requirements
------------
Server/Environment Requirements
-------------------------------

Before upgrading Zikula it's important to ensure that the hosting server environment meets the requirements
of the new core release. Zikula Core 1.4.0 has the following requirements
of the new core release. Zikula Core 1.4.x has the following requirements

| | Minimum | Recommended |
| ------------- |:-------------:| :-----------:|
Expand Down Expand Up @@ -74,7 +74,7 @@ If you store Composer in the root of the Zikula Core checkout, please rename it

####FOR NORMAL USERS: Download the current release from [http://www.zikula.org/](http://www.zikula.org/)

All the dependencies and requirements are included in this package, simply unpack the archive.
All the dependencies and requirements are included in this package.


<a name="upgrading"></a>
Expand All @@ -88,12 +88,14 @@ The following process should be followed for all upgrades even small point relea
`personal_config.php`.
- Make a note of your 'startpage' settings as they must be cleared in the upgrade process.
- Before uploading the new files, delete **all files** in your web root (typically `public_html` or `httpdocs`).
- Upload the new package.
- It is most reliable to upload the archive and the unpack the archive on the server instead of FTP thousands
of small files.
- Windows/FTP users: Take care about copying all files. If there are some files you are not able to
transfer to the server check if your longest path length is longer than Windows/FTP-Software allows (more than
256 characters).
- Upload the new package and unpack the archive.
- **Please read** the [INSTALL docs](INSTALL-1.4.md#upload) for detailed information on proper uploading.
- Note 1: One common issue when installing is that the app/cache and app/logs directories must be writable both by the
web server and the command line user. See Symfony's [Setting up or Fixing File Permissions](http://symfony.com/doc/2.8/setup/file_permissions.html)
to see potential solutions to this problem when installing from the CLI.
- Note 2: If you have `mod_suexec` installed for Apache the CLI will run into permission problems. (If you are not sure
check your phpinfo.) `mod_suexec` often is used in shared hosting environments. In this case, the CLI installer is not
recommended, please use the Web Installer.

#### If upgrading from Core-1.3.x:

Expand All @@ -110,11 +112,10 @@ The following process should be followed for all upgrades even small point relea
#### If upgrading from Core-1.4.x:

- Copy your existing `config/personal_config.php` and `app/config/custom_parameters.yml` to their same respective
locations in your new installation. There is no need to update any values within these files.
locations in your new installation. **There is no need to update any values within these files.**

#### Continue:

- Make `app/cache` and `app/logs` directories writable. (**Zikula WILL NOT install without this critical step**)
- Copy your backup `/userdata` and your **theme** to your new installation. The folders of your theme should be
in the exact same place as your backup.
- **Upgrade: (do one or the other)**
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@
},
"scripts": {
"post-install-cmd": [
"Zikula\\Composer\\CopyRequirementsFile::copy",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Zikula\\Composer\\LessGenerator::generateCombinedBootstrapFontAwesomeCSS",
"Zikula\\Composer\\RequireJsConfigGenerator::regenerateRequireJs"
],
"post-update-cmd": [
"Zikula\\Composer\\CopyRequirementsFile::copy",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
Expand Down
9 changes: 9 additions & 0 deletions src/app/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Zikula\Bundle\CoreBundle\Yaml\Yaml;
use Zikula\Bundle\CoreBundle\Console\Application;

set_time_limit(0);

require __DIR__.'/autoload.php';
require __DIR__.'/ZikulaKernel.php';
require __DIR__.'/../lib/requirementCheck.php';

$getZikulaEnv = function(ArgvInput $input) {
$defaultEnv = $input->getParameterOption(['--env', '-e'], getenv('ZIKULA_ENV') ?: 'dev');
Expand All @@ -27,6 +29,13 @@ if ($debug) {
Debug::enable();
}

// on install or upgrade, check if system requirements are met.
$kernelConfig = Yaml::parse(file_get_contents(__DIR__.'/config/parameters.yml'));
if (is_readable($file = __DIR__.'/config/custom_parameters.yml')) {
$kernelConfig = array_merge($kernelConfig, Yaml::parse(file_get_contents($file)));
}
requirementCheck($kernelConfig['parameters']);

$kernel = new ZikulaKernel($env, $debug);
$kernel->boot();

Expand Down
4 changes: 3 additions & 1 deletion src/lib/Zikula/Bundle/CoreBundle/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ protected function registerCommands()
if ($this->kernel->getContainer()->getParameter('installed') === true) {
// don't attempt to login if the Core needs an upgrade
VersionUtil::defineCurrentInstalledCoreVersion($this->kernel->getContainer());
if (defined('ZIKULACORE_CURRENT_INSTALLED_VERSION') && version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, \Zikula_Core::VERSION_NUM, '==')) {
$currentVersion = $this->kernel->getContainer()->getParameter(\Zikula_Core::CORE_INSTALLED_VERSION_PARAM);
// @todo login is pointless for CLI isn't it?
if (version_compare($currentVersion, \Zikula_Core::VERSION_NUM, '==')) {
try {
$this->loginAsAdministrator();
} catch (\Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION, '<=')) {
$output->writeln($this->translator->__f('The current installed version of Zikula is reporting (%1$s). You must upgrade to version (%2$s) before you can use this upgrade.', ['%1$s' => ZIKULACORE_CURRENT_INSTALLED_VERSION, '%2$s' => UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION]));
$currentVersion = $this->getContainer()->getParameter(\Zikula_Core::CORE_INSTALLED_VERSION_PARAM);
if (version_compare($currentVersion, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION, '<=')) {
$output->writeln($this->translator->__f('The current installed version of Zikula is reporting (%1$s). You must upgrade to version (%2$s) before you can use this upgrade.', ['%1$s' => $currentVersion, '%2$s' => UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION]));

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ private function protectFiles()
// set installed = true
$params = $this->yamlManager->getParameters();
$params['installed'] = true;
// set currently installed version into parameters
$params[\Zikula_Core::CORE_INSTALLED_VERSION_PARAM] = \Zikula_Core::VERSION_NUM;

$this->yamlManager->setParameters($params);
// clear the cache
$this->container->get('zikula.cache_clearer')->clear('symfony.config');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ class AjaxUpgradeController extends AbstractController
*/
private $yamlManager;

/**
* @var string the currently installed core version
*/
private $currentVersion;

public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->yamlManager = new YamlDumper($this->container->get('kernel')->getRootDir() .'/config', 'custom_parameters.yml');
$this->currentVersion = $this->container->getParameter(\Zikula_Core::CORE_INSTALLED_VERSION_PARAM);
}

public function ajaxAction(Request $request)
Expand Down Expand Up @@ -89,7 +95,7 @@ private function executeStage($stageName)

private function installRoutesModule()
{
if (version_compare(\Zikula_Core::VERSION_NUM, '1.4.0', '>') && version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, '1.4.0', '>=')) {
if (version_compare(\Zikula_Core::VERSION_NUM, '1.4.0', '>') && version_compare($this->currentVersion, '1.4.0', '>=')) {
// this stage is not necessary to upgrade from 1.4.0 -> 1.4.x
return true;
}
Expand Down Expand Up @@ -155,7 +161,7 @@ private function regenerateThemes()

private function from140to141()
{
if (version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, '1.4.1', '>=')) {
if (version_compare($this->currentVersion, '1.4.1', '>=')) {
return true;
}
// perform the following SQL
Expand All @@ -178,7 +184,7 @@ private function from140to141()

private function from141to142()
{
if (version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, '1.4.2', '>=')) {
if (version_compare($this->currentVersion, '1.4.2', '>=')) {
return true;
}
// do some clean up
Expand All @@ -191,7 +197,7 @@ private function from141to142()

private function from142to143()
{
if (version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, '1.4.3', '>=')) {
if (version_compare($this->currentVersion, '1.4.3', '>=')) {
return true;
}
// install ZAuth
Expand Down Expand Up @@ -252,6 +258,10 @@ private function finalizeParameters()
$params['router.request_context.host'] = isset($params['router.request_context.host']) ? $params['router.request_context.host'] : $this->container->get('request')->getHost();
$params['router.request_context.scheme'] = isset($params['router.request_context.scheme']) ? $params['router.request_context.scheme'] : 'http';
$params['router.request_context.base_url'] = isset($params['router.request_context.base_url']) ? $params['router.request_context.base_url'] : $this->container->get('request')->getBasePath();

// set currently installed version into parameters
$params[\Zikula_Core::CORE_INSTALLED_VERSION_PARAM] = \Zikula_Core::VERSION_NUM;

$this->yamlManager->setParameters($params);

// store the recent version in a config var for later usage. This enables us to determine the version we are upgrading from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class UpgraderController extends AbstractController
*/
public function upgradeAction(Request $request, $stage)
{
if (version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, \Zikula_Core::VERSION_NUM, '=')) {
$currentVersion = $this->container->getParameter(\Zikula_Core::CORE_INSTALLED_VERSION_PARAM);
if (version_compare($currentVersion, \Zikula_Core::VERSION_NUM, '=')) {
$stage = 'complete';
}
// notinstalled?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public function onCoreInit(GenericEvent $event)
$request = $this->container->get('request');
// create several booleans to test condition of request regarding install/upgrade
$installed = $this->container->getParameter('installed');
$requiresUpgrade = false;
if ($installed) {
VersionUtil::defineCurrentInstalledCoreVersion($this->container);
$currentVersion = $this->container->getParameter(\Zikula_Core::CORE_INSTALLED_VERSION_PARAM);
$requiresUpgrade = $installed && version_compare($currentVersion, \Zikula_Core::VERSION_NUM, '<');
}
$requiresUpgrade = $installed && version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, \Zikula_Core::VERSION_NUM, '<');

// can't use $request->get('_route') to get any of the following
// all these routes are hard-coded in xml files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function getTemplateName()

public function isNecessary()
{
if (version_compare(\Zikula_Core::VERSION_NUM, '1.4.0', '>') && version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, '1.4.0', '>=')) {
$currentVersion = $this->container->getParameter(\Zikula_Core::CORE_INSTALLED_VERSION_PARAM);
if (version_compare(\Zikula_Core::VERSION_NUM, '1.4.0', '>') && version_compare($currentVersion, '1.4.0', '>=')) {
// this stage is not necessary to upgrade from 1.4.0 -> 1.4.x
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public function getTemplateName()

public function isNecessary()
{
if (version_compare(ZIKULACORE_CURRENT_INSTALLED_VERSION, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION, '<=')) {
throw new AbortStageException($this->translator->__f('The current installed version of Zikula is reporting (%1$s). You must upgrade to version (%2$s) before you can use this upgrade.', ['%1$s' => ZIKULACORE_CURRENT_INSTALLED_VERSION, '%2$s' => UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION]));
$currentVersion = $this->container->getParameter(\Zikula_Core::CORE_INSTALLED_VERSION_PARAM);
if (version_compare($currentVersion, UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION, '<=')) {
throw new AbortStageException($this->translator->__f('The current installed version of Zikula is reporting (%1$s). You must upgrade to version (%2$s) before you can use this upgrade.', ['%1$s' => $currentVersion, '%2$s' => UpgraderController::ZIKULACORE_MINIMUM_UPGRADE_VERSION]));
}
// make sure selected language is installed
$DBLocale = $this->fetchDBLocale();
Expand Down
Loading

0 comments on commit 1a6f21a

Please sign in to comment.