Skip to content

Commit

Permalink
Merge pull request #5 from umer936/master
Browse files Browse the repository at this point in the history
Upgrades (CakePHP 3 --> 4, BS 3 --> 5, remove deprecated functions)
  • Loading branch information
anuj9196 authored Oct 27, 2022
2 parents de2ce42 + 9e52882 commit 33ccc5b
Show file tree
Hide file tree
Showing 35 changed files with 571 additions and 798 deletions.
33 changes: 8 additions & 25 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
# CakePHP 3

/vendor/*
/config/app.php

/tmp/cache/models/*
!/tmp/cache/models/empty
/tmp/cache/persistent/*
!/tmp/cache/persistent/empty
/tmp/cache/views/*
!/tmp/cache/views/empty
/tmp/sessions/*
!/tmp/sessions/empty
/tmp/tests/*
!/tmp/tests/empty

/logs/*
!/logs/empty

# CakePHP 2

/app/tmp/*
/app/Config/core.php
/app/Config/database.php
/vendors/*
/composer.lock
/composer.phar
/phpunit.xml
/.phpunit.result.cache
/phpunit.phar
/config/Migrations/schema-dump-default.lock
/vendor/
/.idea/
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Installer plugin for CakePHP

## Version/Update
**Current Version:** 3.0.0
**Last Update:** October 17, 2018
**Current Version:** 4.0.0

**Last Update:** September 22, 2022

**Releases:** [Releases](https://github.com/anuj9196/CakePHP-App-Installer/releases)

## Requirements
#### CakePHP: 3.4+
#### CakePHP: 4.3.0+

## Introduction
This plugin will allow you to Install your CakePHP Application on other server/system using GUI interface like Wordpress, etc.
Expand All @@ -24,3 +24,4 @@ This plugin will allow you to Install your CakePHP Application on other server/s
## Credits
1. @prbaron for providing plugin for old version on CakePHP
2. *Anshuman (my friend)* for asking me to write this plugin
3. @umer936 upgrading to CakePHP 4 compatibility and QOL improvements
26 changes: 16 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
"name": "cakephp-app-installer/installer",
"description": "GUI Installer Plugin for CakePHP",
"type": "cakephp-plugin",
"keywords": ["cakephp", "cakephp-3.3", "cakephp-3", "app-installer", "installer", "CakePHP-GUI-Installer"],
"keywords": [
"cakephp",
"cakephp-4",
"app-installer",
"installer",
"CakePHP-GUI-Installer"
],
"homepage": "https://github.com/anuj9196/CakePHP-App-Installer",
"require": {
"cakephp/cakephp": "^3.3"
"php": ">=7.2",
"cakephp/cakephp": "^4.3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7|^6.0"
"phpunit/phpunit": "@stable"
},
"license": "MIT",
"authors": [
Expand All @@ -18,19 +25,18 @@
}
],
"support": {
"issues": "https://github.com/anuj9196/CakePHP-App-Installer/issues",
"source": "https://github.com/anuj9196/CakePHP-App-Installer"
"issues": "https://github.com/anuj9196/CakePHP-App-Installer/issues",
"source": "https://github.com/anuj9196/CakePHP-App-Installer"
},
"autoload": {
"psr-4": {
"Installer\\": "src"
"CakePHPAppInstaller\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Installer\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
"CakePHPAppInstaller\\Test\\": "tests/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
}
},
"minimum-stability": "dev"
}
}
4 changes: 2 additions & 2 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
/**
* Database installation variable
* if set to TRUE, the database is installed
* if set to FALSE, the databse is not installed
* if set to FALSE, the database is not installed
*/
Configure::write('Database.installed', false);

Configure::load('Installer.defaults');
Configure::load('CakePHPAppInstaller.defaults');
collection((array)Configure::read('Installer.config'))->each(function ($file) {
Configure::load($file);
});
8 changes: 6 additions & 2 deletions config/database.php.install → config/database_install.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

use Cake\Database\Driver\Mysql;
use Cake\Database\Connection;

return [
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'className' => Connection::class,
'driver' => Mysql::class,
'persistent' => false,
'host' => '{default_host}',
/**
Expand Down
9 changes: 6 additions & 3 deletions config/defaults.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php
// Default settings for the installer
use Cake\Database\Driver\Mysql;
use Cake\Database\Connection;

return [
'Installer' => [
// Default database connection settings
'Connection' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'className' => Connection::class,
'driver' => Mysql::class,
'persistent' => false,
'host' => 'localhost',
'username' => 'root',
Expand All @@ -32,7 +35,7 @@
'database_php' => [
'use' => true,
'filename' => 'database.php',
'default' => PLUGIN_CONFIG . 'database.php.install',
'default' => PLUGIN_CONFIG . 'database_install.php',
],

// These are common optional config files. If you use them, you must provide your own
Expand Down
11 changes: 7 additions & 4 deletions config/routes.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php
/**
* @var \Cake\Routing\RouteBuilder $routes
*/

use Cake\Routing\RouteBuilder;
use Cake\Routing\Router;
use Cake\Routing\Route\DashedRoute;

Router::plugin(
'Installer',
$routes->plugin(
'CakePHPAppInstaller',
['path' => '/installer'],
function (RouteBuilder $routes) {
static function (RouteBuilder $routes) {
$routes->connect('/', ['controller' => 'Install', 'action' => 'index']);
$routes->fallbacks(DashedRoute::class);
}
Expand Down
12 changes: 6 additions & 6 deletions docs/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Plugin will autocheck for database configuration and let you re-configure databa
Add following lines to your `beforeRender` function of **AppController.php**

```
$this->loadComponent('Installer.Install');
if ($this->request->params['plugin'] !== 'Installer') {
$this->loadComponent('CakePHPAppInstaller.Install');
if ($this->request->params['plugin'] !== 'CakePHPAppInstaller') {
$this->Install->installationCheck();
}
```
Expand All @@ -35,16 +35,16 @@ Your `beforeRender` function then looks like
```
public function beforeRender(Event $event)
{
$this->loadComponent('Installer.Install');
if ($this->request->params['plugin'] !== 'Installer') {
$this->Install->installationCheck();
$this->loadComponent('CakePHPAppInstaller.Install');
if ($this->request->params['plugin'] !== 'CakePHPAppInstaller') {
$this->CakePHPAppInstaller->installationCheck();
}
...
...
...
}
```

**That's it** Now whenever there is database connectivity failure, you will be asked to reconfigure your application.

[< Importing Schema](import-schema.md) | [README](../README.md) | [Credits >](../README.md#credits)
17 changes: 7 additions & 10 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,26 @@ composer require cakephp-app-installer/installer
#### Step 2:
load Installer plugin to your CakePHP Application by adding below like to your **bootstrap.php** file inside */config* directory
```
Plugin::load('Installer', ['bootstrap' => true, 'routes' => true]);
Plugin::load('CakePHPAppInstaller', ['bootstrap' => true, 'routes' => true]);
```
or from terminal
```
bin/cake plugin load Installer -b -r
bin/cake plugin load CakePHPAppInstaller
```

## Setup
below following script inside **bootstrap.php** file in */config* directory
```
try {
Configure::config('default', new PhpConfig());
Configure::load('app', 'default', false);
} catch (\Exception $e) {
exit($e->getMessage() . "\n");
if (file_exists(CONFIG . 'app_local.php')) {
Configure::load('app_local', 'default');
}
...
```
add following lines
```
try {
...
if (file_exists(CONFIG . 'database.php')) {
Configure::load('database', 'default');
} catch (\Exception $e) {
}
```

Expand Down
24 changes: 8 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
bootstrap="tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
Expand All @@ -13,26 +12,19 @@

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="Installer Test Suite">
<directory>./tests/TestCase</directory>
<testsuite name="CakePHPAppInstaller">
<directory>tests/TestCase/</directory>
</testsuite>
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
</listener>
</listeners>
<!-- Setup fixture extension -->
<extensions>
<extension class="Cake\TestSuite\Fixture\PHPUnitExtension" />
</extensions>

<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

</phpunit>
22 changes: 10 additions & 12 deletions src/Controller/AppController.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?php
namespace Installer\Controller;
declare(strict_types=1);

namespace CakePHPAppInstaller\Controller;

use App\Controller\AppController as BaseController;
use Cake\Event\Event;
use Cake\Event\EventInterface;

class AppController extends BaseController
{
/**
* @param \Cake\Event\Event $event The beforeRender event.
* @return \Cake\Http\Response|null|void
*/
public function beforeRender(Event $event)
public function beforeRender(EventInterface $event)
{
try {
return parent::beforeRender($event);
} finally {
$this->viewBuilder()->setTheme(null);
}
try {
return parent::beforeRender($event);
} finally {
$this->viewBuilder()->setTheme(null);
}
}
}
Loading

0 comments on commit 33ccc5b

Please sign in to comment.