Closed kousu closed 6 years ago
I just tried running this code on php7.2 and got a big angry traceback:
( ! ) Fatal error: Cannot use 'Object' as class name as it is reserved in /var/www/feastdb/public/vol2/lib/Cake/Core/Object.php on line 26
Call Stack
# Time Memory Function Location
1 0.0007 396472 {main}( ) .../index.php:0
2 0.0197 398512 include( '/var/www/feastdb/public/vol2/lib/Cake/bootstrap.php' ) .../index.php:77
3 0.0496 591544 Configure::bootstrap( ) .../bootstrap.php:146
4 0.0679 743480 class_exists ( ) .../Configure.php:105
5 0.0679 743512 spl_autoload_call ( ) .../Configure.php:105
6 0.0679 743544 App::load( ) .../Configure.php:105
7 0.0686 883088 App::shutdown( ) .../App.php:0
8 0.0687 883080 App::_checkFatalError( ) .../App.php:899
9 0.0688 883760 ErrorHandler::handleError( ) .../App.php:926
10 0.0688 883760 ErrorHandler::handleFatalError( ) .../ErrorHandler.php:161
11 0.0837 886888 ErrorHandler::handleException( ) .../ErrorHandler.php:211
12 0.1015 889880 ExceptionRenderer->__construct( ) .../ErrorHandler.php:125
13 0.1015 889880 ExceptionRenderer->_getController( ) .../ExceptionRenderer.php:93
14 0.1085 966696 spl_autoload_call ( ) .../ExceptionRenderer.php:157
15 0.1085 966736 App::load( ) .../ExceptionRenderer.php:157
16 0.1109 972464 include( '/var/www/feastdb/public/vol2/lib/Cake/Controller/Controller.php' ) .../App.php:560
17 0.1109 973744 spl_autoload_call ( ) .../Controller.php:56
18 0.1109 973776 App::load( ) .../Controller.php:56
And on php7.0 it gets further but still chokes with
Fatal Error
Error: Cannot use 'String' as class name as it is reserved File: /var/www/feastdb/public/vol2/lib/Cake/Utility/String.php Line: 26
Notice: If you want to customize this error message, create app/View/Errors/fatal_error.ctp
It won't even fully work on php5.6. The only compatible version is php5.5 which is not getting security updates anymore.
There's a migration guide to go from 2.x -> 3.0, and further guides for the minor steps. Right now I'm guess that the best path is to go to 3.0 and then go step by step after that. Especially since there's a tool that handles going -> 3.0 but not further.
3.0 rearranges the folder structure and replaces the ORM, so just getting those working are going to be a pretty big change, I think. And there's to see how #4 fits in after the update too.
In the old app layout, CakePHP was installed to lib/
; now it's expected to be installed to vendor/
by Composer.
It seems like, thankfully (and correctly), no changes were made to CakePHP in the old location, so we should just be able to delete it from there:
$ git log lib
commit 4e3bf873559dbffa7e1cf9f5da3e6750900619a5
Author: Nick Guenther <kousu@santropolroulant.org>
Date: Thu May 31 02:39:44 2018 -0400
Run CakePHP 2-to-3 migration tool.
From https://github.com/cakephp/upgrade
commit b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16
Author: itsupport <itsupport@santropolroulant.org>
Date: Thu Oct 11 20:00:30 2012 +0530
Import CakePHP
And the app skeleton app/
has been split between ./
and src/
, I think. The upgrade tool was smart enough to rename some folders (eg app/{View => src/Template}
), but it kept everything in app/
; I suspect I should just move everything in there up a folder, to match the structure in https://github.com/cakephp/app.
To double check that, I followed the skeleton instructions from scratch:
$ composer create-project --prefer-dist cakephp/app dssd
Installing cakephp/app (3.6.1)
- Installing cakephp/app (3.6.1): Loading from cache
Created project in dssd
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 48 installs, 0 updates, 0 removals
- Installing cakephp/plugin-installer (1.1.0): Loading from cache
...
Writing lock file
Generating autoload files
> Cake\Composer\Installer\PluginInstaller::postAutoloadDump
> App\Console\Installer::postInstall
Created `config/app.php` file
...
Updated Security.salt value in config/app.php
And then ran a diff:
...
Beware: app/config/bootstrap.php
was edited to add helper functions globally; these should probably have been done in a plugin or something more framework-friendly.
Note to self: @connorbode has included a Dockerfile; I need to double-check that's still working after the upgrade.
Let's index what was modified in the original app skeleton:
diff -ru dssd/ ../santropol/volunteerdb/app/ > skel.patch.txt
Almost all of the edits were in app/
$ git diff b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/ | wc
10675 40836 526074
$ git diff b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- ./ | wc
10980 42141 535786
And those not in app/ were independent metafiles (in fact, the largest portions are from Connor's recent work):
diff --git a/.gitignore b/.gitignore
index de4f6ff0b..e3849b952 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,5 @@
/dist
.DS_Store
/tags
+migrate.php
+dump_njk.sql
diff --git a/.htaccess b/.htaccess
index f23dbaf66..417c61355 100644
--- a/.htaccess
+++ b/.htaccess
@@ -2,4 +2,4 @@
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
-</IfModule>
\ No newline at end of file
+</IfModule>
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..cca06cb4e
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,20 @@
+FROM php:5-apache
+MAINTAINER pierangelo orizio <pierangelo1982@gmail.com>
+
+WORKDIR /var/www/html
+
+COPY ./default.conf /etc/apache2/sites-available/000-default.conf
+
+RUN docker-php-ext-install pdo pdo_mysql
+
+RUN apt-get update && \
+ apt-get -y install curl git libicu-dev libpq-dev zlib1g-dev zip && \
+ docker-php-ext-install intl mbstring pcntl pdo_mysql pdo_pgsql zip && \
+ usermod -u 1000 www-data && \
+ usermod -a -G users www-data && \
+ chown -R www-data:www-data /var/www && \
+ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && \
+ a2enmod rewrite
+
+
+COPY . /var/www/html
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 000000000..ce0957369
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2014 Nicolas Kruchten
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index 611729f08..3d3dc03e3 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,31 @@
+Santropol Volunteer DB
+======================
+
+## Development setup
+
+1. [Install Docker Compose](https://docs.docker.com/compose/install/)
+2. Create the database connection file at `app/Config/database.php`:
+ ```
+ <?php
+ class DATABASE_CONFIG {
+ public $default = array(
+ 'datasource' => 'Database/Mysql',
+ 'persistent' => false,
+ 'host' => 'db',
+ 'login' => 'root',
+ 'password' => 'password',
+ 'database' => 'database',
+ 'prefix' => 'vol2_'
+ );
+ }
+ ```
+2. From the project root, run `docker-compose up`
+3. The application should now be running on `http://localhost:8090`
+
+
+
+
+
CakePHP
=======
diff --git a/TODO b/TODO
new file mode 100644
index 000000000..2c8d5a1be
--- /dev/null
+++ b/TODO
@@ -0,0 +1,6 @@
+Orientation date
+advanced search
+language graphs inc unknown
+db field fill rates
+volunteers over time graphs
+bilingual db
diff --git a/db.sql b/db.sql
new file mode 100644
index 000000000..5eebfed67
--- /dev/null
+++ b/db.sql
@@ -0,0 +1,43 @@
+CREATE TABLE `vol2_volunteers` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `created` datetime DEFAULT NULL,
+ `modified` datetime DEFAULT NULL,
+ `orientationdate` date DEFAULT NULL,
+
+ `firstname` varchar(50) DEFAULT NULL,
+ `lastname` varchar(50) DEFAULT NULL,
+ `searchableName` varchar(200) DEFAULT NULL,
+ `birthyear` int(11) DEFAULT NULL,
+ `birthmonth` int(11) DEFAULT NULL,
+ `birthday` int(11) DEFAULT NULL,
+
+ `phone1` varchar(20) DEFAULT NULL,
+ `phone2` varchar(20) DEFAULT NULL,
+ `phone3` varchar(20) DEFAULT NULL,
+ `email` varchar(200) DEFAULT NULL,
+ `address` text,
+ `emergname` varchar(50) DEFAULT NULL,
+ `emergrelation` varchar(50) DEFAULT NULL,
+ `emergphone1` varchar(20) DEFAULT NULL,
+ `emergphone2` varchar(20) DEFAULT NULL,
+ `emergphone3` varchar(20) DEFAULT NULL,
+ `emergemail` varchar(50) DEFAULT NULL,
+
+ `occupation` varchar(50) DEFAULT NULL,
+ `occupationother` text,
+ `foundout` varchar(50) DEFAULT NULL,
+ `foundoutother` text,
+ `language1` varchar(50) DEFAULT NULL,
+ `language2` varchar(50) DEFAULT NULL,
+ `language3` varchar(50) DEFAULT NULL,
+ `language4` varchar(50) DEFAULT NULL,
+ `language5` varchar(50) DEFAULT NULL,
+
+ `occupation2` varchar(50) DEFAULT NULL,
+ `occupation3` varchar(50) DEFAULT NULL,
+
+ `foundout2` varchar(50) DEFAULT NULL,
+ `foundout3` varchar(50) DEFAULT NULL,
+
+ PRIMARY KEY (`id`)
+);
diff --git a/default.conf b/default.conf
new file mode 100644
index 000000000..523ea01dc
--- /dev/null
+++ b/default.conf
@@ -0,0 +1,35 @@
+<VirtualHost *:80>
+ # The ServerName directive sets the request scheme, hostname and port that
+ # the server uses to identify itself. This is used when creating
+ # redirection URLs. In the context of virtual hosts, the ServerName
+ # specifies what hostname must appear in the request's Host: header to
+ # match this virtual host. For the default virtual host (this file) this
+ # value is not decisive as it is used as a last resort host regardless.
+ # However, you must set it for any further virtual host explicitly.
+ #ServerName www.example.com
+
+ ServerAdmin webmaster@localhost
+ DocumentRoot /var/www/html/app/webroot
+
+ <Directory /var/www/html/app/webroot>
+ Options FollowSymLinks
+ AllowOverride all
+ Require all granted
+ </Directory>
+
+ # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
+ # error, crit, alert, emerg.
+ # It is also possible to configure the loglevel for particular
+ # modules, e.g.
+ #LogLevel info ssl:warn
+
+ ErrorLog ${APACHE_LOG_DIR}/error.log
+ CustomLog ${APACHE_LOG_DIR}/access.log combined
+
+ # For most configuration files from conf-available/, which are
+ # enabled or disabled at a global level, it is possible to
+ # include a line for only one particular virtual host. For example the
+ # following line enables the CGI configuration for this host only
+ # after it has been globally disabled with "a2disconf".
+ #Include conf-available/serve-cgi-bin.conf
+</VirtualHost>
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 000000000..2dfececbc
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,31 @@
+version: '2'
+services:
+ web:
+ build: .
+ ports:
+ - "8090:80"
+ volumes:
+ - .:/var/www/html
+ depends_on:
+ - db
+ links:
+ - db
+ db:
+ image: "mysql:5.7"
+ environment:
+ - MYSQL_ROOT_PASSWORD=password
+ - MYSQL_DATABASE=database
+ ports:
+ - "3306:3306"
+ volumes:
+ - ./initdb.d:/docker-entrypoint-initdb.d
+ phpmyadmin:
+ depends_on:
+ - db
+ image: phpmyadmin/phpmyadmin
+ restart: always
+ ports:
+ - 8081:80
+ environment:
+ PMA_HOST: db
+ MYSQL_ROOT_PASSWORD: password
\ No newline at end of file
diff --git a/initdb.d/1.sql b/initdb.d/1.sql
new file mode 100644
index 000000000..73850ba92
--- /dev/null
+++ b/initdb.d/1.sql
@@ -0,0 +1,47 @@
+DROP TABLE IF EXISTS `vol2_volunteers`;
+CREATE TABLE `vol2_volunteers` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `created` datetime DEFAULT NULL,
+ `modified` datetime DEFAULT NULL,
+ `orientationdate` date DEFAULT NULL,
+ `firstname` varchar(50) DEFAULT NULL,
+ `lastname` varchar(50) DEFAULT NULL,
+ `searchableName` varchar(200) DEFAULT NULL,
+ `birthyear` int(11) DEFAULT NULL,
+ `birthmonth` int(11) DEFAULT NULL,
+ `birthday` int(11) DEFAULT NULL,
+ `phone1` varchar(20) DEFAULT NULL,
+ `phone2` varchar(20) DEFAULT NULL,
+ `phone3` varchar(20) DEFAULT NULL,
+ `email` varchar(200) DEFAULT NULL,
+ `address` text,
+ `emergunable` bool DEFAULT 0,
+ `emergname` varchar(200) DEFAULT NULL,
+ `emergrelation` varchar(50) DEFAULT NULL,
+ `emergphone1` varchar(20) DEFAULT NULL,
+ `emergphone2` varchar(20) DEFAULT NULL,
+ `emergphone3` varchar(20) DEFAULT NULL,
+ `emergemail` varchar(50) DEFAULT NULL,
+ `emergname` varchar(200) DEFAULT NULL,
+ `emergrelation` varchar(50) DEFAULT NULL,
+ `emergphone1` varchar(20) DEFAULT NULL,
+ `emergphone2` varchar(20) DEFAULT NULL,
+ `emergphone3` varchar(20) DEFAULT NULL,
+ `emergemail` varchar(50) DEFAULT NULL,
+ `occupation` varchar(50) DEFAULT NULL,
+ `occupationother` text,
+ `foundout` varchar(50) DEFAULT NULL,
+ `foundoutother` text,
+ `language1` varchar(50) DEFAULT NULL,
+ `language2` varchar(50) DEFAULT NULL,
+ `language3` varchar(50) DEFAULT NULL,
+ `language4` varchar(50) DEFAULT NULL,
+ `language5` varchar(50) DEFAULT NULL,
+ `occupation2` varchar(50) DEFAULT NULL,
+ `occupation3` varchar(50) DEFAULT NULL,
+ `foundout2` varchar(50) DEFAULT NULL,
+ `foundout3` varchar(50) DEFAULT NULL,
+ `notes` varchar(5000) DEFAULT NULL,
+ `mediapermission` tinyint(1) DEFAULT 1
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=6057 DEFAULT CHARSET=latin1;
\ No newline at end of file
So, for the parts in app/, here's the edits that were done piece-by-piece:
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Config | wc
219 805 6230
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Console | wc
0 0 0
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Controller/ | wc
92 381 3554
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/.htaccess | wc
11 34 294
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/index.php | wc
0 0 0
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Lib | wc
0 0 0
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Locale | wc
0 0 0
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Model/ | wc
10 32 245
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Plugin/ | wc
0 0 0
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Test/ | wc
0 0 0
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/tmp | wc
18 60 574
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/Vendor/ | wc
0 0 0
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/View/ | wc
1019 3744 32380
$ git diff -D b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/webroot/ | wc
9306 35780 482797
The bulk of the edits are in webroot/, which turn out to just be copying in bootstrap and jquery, i.e. files we don't need to worry about
$ git log --stat b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD -- app/webroot/
commit 4d926382497d16d7164422421a2a526ec305c477
Author: Nicolas Kruchten <nicolas@kruchten.com>
Date: Sun Jan 12 16:09:11 2014 -0500
final commit
app/webroot/css/datepicker.css | 7 ++
app/webroot/js/bootstrap-datepicker.js | 454 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
app/webroot/js/jquery-1.8.3.min.js | 2 +
app/webroot/js/jquery.placeholder.min.js | 11 ++
4 files changed, 474 insertions(+)
commit 88c9ab75dae1fd0dd52719312676583bbaf90351
Author: Nicolas Kruchten <nicolas@kruchten.com>
Date: Sat Oct 13 17:24:01 2012 -0400
first roundtrip
app/webroot/css/bootstrap.css | 5837 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
app/webroot/css/bootstrap.min.css | 841 ++++++++++
app/webroot/js/bootstrap.js | 2038 ++++++++++++++++++++++++
app/webroot/js/bootstrap.min.js | 7 +
app/webroot/js/jquery.validate.min.js | 51 +
5 files changed, 8774 insertions(+)
So we need to investigate:
The Views are where most of the work is; they're essentially all the HTML pages. It's also likely that most of them are new files so mostly they shouldn't conflict with the updated app skeleton. Indeed, looking at it, all the changes are new files in app/View/Volunteers/ and app/View/Elements/flash_.ctp, except for app/View/Layouts/default.ctp which would conflict --- but I think we should just not worry about it, because that's probably the master layout template, and whatever @nicolaskruchten decided was best should rule; anyway, the original default.ctp is pretty short so if there is anything to learn from it we should be able to figure it out quick.
The edits to tmp are just setting file permissions, which are probably an artifact of the upgrade tool or something anyway, so I'll ignore that.
Model/ just adds a new file, Volunteer.php, which is the backing for app/View/Volunteer/, so that's no conflict.
.htaccess only got edited incidentally: "\ No newline at end of file", so that's ignorable.
Controller contains, again, just a single new file for Volunteers.
Config is where the next largest batch of work is; but investigating, that's actually mostly the helper functions that @nicolaskruchten dumped into bootstrap.php (and probably those functions should be pulled elsewhere (Plugins/?)). There's also an edit to routes.php:
+
diff --git a/app/Config/routes.php b/app/Config/routes.php
index 32151d27c..93cf40e94 100644
--- a/app/Config/routes.php
+++ b/app/Config/routes.php
@@ -25,7 +25,7 @@
* its action called 'display', and we pass a param to select the view file
* to use (in this case, /app/View/Pages/home.ctp)...
*/
- Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
+ Router::connect('/', array('controller' => 'Volunteers', 'action' => 'index', 'home'));
/**
* ...and connect the rest of 'Pages' controller's urls.
*/
@@ -42,3 +42,5 @@
* the built-in default routes.
*/
require CAKE . 'Config' . DS . 'routes.php';
+
+ Router::parseExtensions('json');
a meaningless change to database.php.default, and some edits to Config/core.php, which I think has been supplanted by app.php, but I don't think any of those edits are meaningful so we can probably just delete that file:
diff --git a/app/Config/core.php b/app/Config/core.php
index 4bbfabe6e..6dccc26a0 100644
--- a/app/Config/core.php
+++ b/app/Config/core.php
@@ -92,7 +92,7 @@
*
* And uncomment the App.baseUrl below:
*/
- //Configure::write('App.baseUrl', env('SCRIPT_NAME'));
+ #Configure::write('App.baseUrl', env('SCRIPT_NAME'));
/**
* Uncomment the define below to use CakePHP prefix routes.
@@ -184,12 +184,12 @@
/**
* A random string used in security hashing methods.
*/
- Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
+ Configure::write('Security.salt', 'DYhG93c0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
/**
* A random numeric string (digits only) used to encrypt/decrypt strings.
*/
- Configure::write('Security.cipherSeed', '76859309657453542496749683645');
+ Configure::write('Security.cipherSeed', '76839309657453542496749683645');
/**
* Apply timestamps with the last modified time to static assets (js, css, images).
@@ -229,7 +229,7 @@
* Uncomment this line and correct your server timezone to fix
* any date & time related errors.
*/
- //date_default_timezone_set('UTC');
+ date_default_timezone_set('UTC');
So I think in all that, the only changes I need to merge manually is the one that makes Volunteers the default route, regenerating the config file from the new template--which actually shouldn't be anything since the only edit to the config was setting the timezone to UTC, which the new template already does, and that I need to move all the files up a level. And then I'll have to go find what files are dead and cull them.
Oh also there's config/schema/*.sql in the new app skeleton, which presumably I should merge the ad-hoc db.sql file into.
How are we supposed to set the seed in deployment? It's generated during composer install cakephp
.
I looked at my demo folder, and apparently it copies app.default.php and makes one edit to it, putting a generated salt into it. I think what you're supposed to do, guessing a bit here because I'm not usually a php programmer and certainly not a modern dependency-managed(!) php programmer, but I think you're supposed to edit app.default.php to set any important settings, then git clone
the repo to a server, then composer install
in the root which reads composer.json. So that's actually not too bad.
And after all the file updates, I probably have to go read that ORM migration guide and change the Model files a bunch.
I almost feel like, given that there's really not very much code here to worry about migrating, it is easier to rm
all files, start from the app template, and reinstall the Volunteers Model/View/Controllers, default.ctp, and the helpers from bootstrap.php; I would (might? git's pretty smart if I nudge it with careful git add
and git rm
s) lose the git history though.
For interest, here's all those new files I would have to manually re-add:
$ git diff --compact-summary b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD | grep '(new'
Dockerfile (new) | 20 +
LICENSE (new) | 21 +
TODO (new) | 6 +
app/Controller/VolunteersController.php (new) | 86 +
app/Model/Volunteer.php (new) | 3 +
app/View/Elements/flash_failure.ctp (new) | 4 +
app/View/Elements/flash_success.ctp (new) | 4 +
app/View/Volunteers/delete.ctp (new) | 1 +
app/View/Volunteers/edit.ctp (new) | 531 +++
app/View/Volunteers/index.ctp (new) | 28 +
app/View/Volunteers/json/search.ctp (new) | 8 +
app/View/Volunteers/search.ctp (new) | 20 +
app/View/Volunteers/view.ctp (new) | 228 +
app/webroot/css/bootstrap.css (new +x) | 5837 +++++++++++++++++++++++
app/webroot/css/bootstrap.min.css (new +x) | 841 ++++
app/webroot/css/datepicker.css (new +x) | 7 +
app/webroot/js/bootstrap-datepicker.js (new +x) | 454 ++
app/webroot/js/bootstrap.js (new +x) | 2038 ++++++++
app/webroot/js/bootstrap.min.js (new +x) | 7 +
app/webroot/js/jquery-1.8.3.min.js (new) | 2 +
app/webroot/js/jquery.placeholder.min.js (new) | 11 +
app/webroot/js/jquery.validate.min.js (new) | 51 +
db.sql (new) | 43 +
default.conf (new) | 35 +
docker-compose.yml (new) | 31 +
initdb.d/1.sql (new) | 47 +
and the modifications
$ git diff --compact-summary b0bc3584a2b7aa64ea0f6c3d3104de2b0f424b16 HEAD | grep -v '(new'
.gitignore | 2 +
.htaccess | 2 +-
README.md | 28 +
app/.htaccess | 2 +-
app/Config/bootstrap.php | 120 +-
app/Config/core.php | 8 +-
app/Config/database.php.default | 8 +-
app/Config/routes.php | 4 +-
app/View/Layouts/default.ctp | 132 +-
app/tmp/cache/models/empty (mode +x) | 0
app/tmp/cache/persistent/empty (mode +x) | 0
app/tmp/cache/views/empty (mode +x) | 0
app/tmp/logs/empty (mode +x) | 0
app/tmp/sessions/empty (mode +x) | 0
app/tmp/tests/empty (mode +x) | 0
of which default.ctp should just be copied in full, and routes.php's one change should be merged and bootstrap.php's many changes should be merged, and database.php.default should be erased in favour of installation instructions in README.md explaining to edit config/app.php. Oh and .gitignore and README.md should be copied; and the old CakePHP template culled from the README.
Edit: oh and flash_*.ctp are redundant because the template has renamed and prettied them up already:
$ diff -u app/src/src/Template/Element/flash_failure.ctp src/Template/Element/Flash/error.ctp
--- app/src/src/Template/Element/flash_failure.ctp 2018-06-03 00:41:31.583945569 -0400
+++ src/Template/Element/Flash/error.ctp 2018-06-03 00:29:40.500150846 -0400
@@ -1,4 +1,6 @@
-<div class="alert alert-error">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <?php echo $message ?>
-</div>
\ Pas de fin de ligne à la fin du fichier
+<?php
+if (!isset($params['escape']) || $params['escape'] !== false) {
+ $message = h($message);
+}
+?>
+<div class="message error" onclick="this.classList.add('hidden');"><?= $message ?></div>
$ diff -u app/src/src/Template/Element/flash_success.ctp src/Template/Element/Flash/success.ctp
--- app/src/src/Template/Element/flash_success.ctp 2018-06-03 00:41:31.583945569 -0400
+++ src/Template/Element/Flash/success.ctp 2018-06-03 00:29:40.500150846 -0400
@@ -1,4 +1,6 @@
-<div class="alert alert-success">
- <button type="button" class="close" data-dismiss="alert">×</button>
- <?php echo $message ?>
-</div>
\ Pas de fin de ligne à la fin du fichier
+<?php
+if (!isset($params['escape']) || $params['escape'] !== false) {
+ $message = h($message);
+}
+?>
+<div class="message success" onclick="this.classList.add('hidden')"><?= $message ?></div>
the one merge I might do is tweaking the css classes there, because the classes in the old files are probably out of the bootstrap.css thingy.
Okay! Progress!
$ composer install
Generating autoload files
> Cake\Composer\Installer\PluginInstaller::postAutoloadDump
> App\Console\Installer::postInstall
Created `config/app.php` file
...
Updated Security.salt value in config/app.php
$
$ php index.php
PHP Fatal error: Class 'app\Controller\AppController' not found in volunteerdb/src/Controller/VolunteersController.php on line 4
Fatal error: Class 'app\Controller\AppController' not found in volunteerdb/src/Controller/VolunteersController.php on line 4
Fatal Error: Class 'app\Controller\AppController' not found in [volunteerdb/src/Controller/VolunteersController.php, line 4]
It's not working, but it's obvious why it's not working: the old code needs patching. But this means the old code is running. So hats off!
I set up a testing DB with a few fake volunteers in the table, and configured it in the generated (and .gitignore
d!) app.php, which took a while, but now I can test the ORM.
To update the ORM, I can just start hitting all the endpoints and seeing what breaks and reading along until I get it; CakePHP has a really stupidly helpful debug console when in debug mode.
The endpoints are named after the View paths:
$ ls src/Template/Volunteers/
delete.ctp edit.ctp json search.ctp upcoming_birthdays.ctp view.ctp
so we have
ORM updates discovered:
conditions = array("column" => array(...))
has to become ->where(["column IN" => array(...)])
› $this->Session->setFlash('Deleted.', 'flash_success'); ^ this is probably going to need editing since I used Template/Element/Flash/success.ctp not Template/Element/flash_success.ctp.
Other updates needed:
$this->webroot
=> $this->request->getAttribute("webroot")
; otherwise you get this very strange error
Error: webrootHelper could not be found.
Error: Create the class webrootHelper below in file: src/View/Helper/webrootHelper.php
<?php
namespace App\View\Helper;
use Cake\View\Helper;
class webrootHelper extends Helper
{
}
But better than that, you use Html's ->css()
, ->js()
and ->link()
functions or better yet Router::url()
. TODO
$this->request->data
doesn't seem to be in use anymore?
I've got the edit form rendering but it won't fill in data from the database. What do?
The migration guide has notes about this. A lot of notes actually. I'll have to see..
EDIT got it: new Form($dataset, $options)
instead of new Form($options)
.
TODO: labels should be redone with Label()
.
And the other form elements should be redone with text()
or select()
There's a weirdness with birthdays (see #5 for initial source of weirdness): if you edit a volunteer that doesn't have a birthday then it ends up saving their birthday as (null, 1, null) because the default for birthmonth is January, there's no null option available on the form. And then when you get bounced to view/
<?php $age = (new DateTime($v['birthyear'] . '-' . $v['birthmonth'] . '-' . $v['birthday']))->diff(....
crashes, because it runs new DateTime("-1-")
.
Is this bug in the pre-3.0 install?? Edit: just looked: not it's not a bug in the pre-3.0 install. The form there generates
<select name="data[Volunteer][birthmonth]" id="VolunteerBirthmonth">
<option value=""></option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
Wow, ambitious upgrade! Looking forward to seeing how it ends up :)
TODO: the HTML pages are all under src/Template/Volunteers/*.ctp but there's also a src/View folder. Doesn't "Template" seem like the wrong place? Templates are for, say, default.ctp, the outer layout wrappers, not the actual views.
I've got it working locally in https://github.com/santropolroulant/volunteerdb/tree/migrate-to-3.
Still to do:
$this->request->getAttribute("webroot") . $something
with ~Router::url()
~Url->build()
or Html::link()
; also Html::css(), Html::script()edit.ctp
to use the specialized calls<input type="hidden" name="_method" value="PUT"/>
in the generated edit page. That's probably... something. What is that doing there? It's not in edit.ctpThis will POST the form data to the add() action of ArticlesController. However, you can also use the same logic to create an edit form. The FormHelper uses the Entity object to automatically detect whether to create an add or edit form. If the provided entity is not ‘new’, the form will be created as an edit form.
<input type="tel">
type=search
Reference on MySQL encoding pain points; and this.
In short: combining web frameworks + mysql can lead to sending utf-8 into the database, which mis-stores it as ascii, but which sends it back without conversion so it comes back out right when it goes back through the UTF-8 driver in the framework. To convince MySQL to understand UTF-8 internally -- in order to get it to do sorting and searching with UTF-8 for us -- you need do:
mysqldump --skip-set-charset --default-character-set=latin1 volunteerdb > volunteerdb.sql
then edit the .sql file in a UTF-8 capable editor to change everywhere it says 'latin1' or 'utf8' to 'utf8mb', especially the SET NAMES 'latin1'
line.
This project was written 6 years ago and CakePHP has had many many revisions since then.