From bbdc9f2ea1ce5205f6f8c3e2aead0e7991a26392 Mon Sep 17 00:00:00 2001 From: Tiana Rakoto Arimanana <5566338+b23prodtm@users.noreply.github.com> Date: Sun, 25 Nov 2018 22:41:50 +0100 Subject: [PATCH] Feature/patch travis composer (#34) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * https://github.com/composer/composer/issues/7797 * Delete composer.phar * fix syntax error, unexpected '$index' * fix 'SQL‘ not found coveralls * Plugin bootstrap Scripts saved args (set -- $saved) * php composer.phar * sql info * bootstrap test * Test Workflow wip : Cannot declare class Tableau, because the name is already in use * HOW to fix issues Error handling upon first tests * ./test_cake.sh -p -t * ERROR 1064 (42000) at line 4 in file: 'app/Config/identities.sql': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if not exists 'test'@'localhost'' at line 1 * Readme * Remote CI : mysql socket ERROR 1064 (42000) at line 4 in file: 'app/Config/identities.sql': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if not exists 'test'@'127.0.0.1'' at line 1 * COLLECT_COVERAGE coveralls php unit bootstrap * environment variable * Documentation * ./Scripts/bootstrap.sh: line 35: ./app/vendor/bin/phpunit: No such file or directory * style * errno : 1054 sqlstate : 42S22 error : Unknown column 'image' in 'field list' Fatal error: CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your /cake core directory and your /vendors root directory. in /home/travis/build/b23prodtm/myphpcms/app/bootstrap_phpunit.php on line 86 * Update php_cms Fatal error: require(): Failed opening required '' (include_path='.:/home/travis/.phpenv/versions/5.6.32/share/pear') in /home/travis/build/b23prodtm/myphpcms/app/webroot/php_cms/e13/include/SQL.php on line 11 --- .gitignore | 3 +- .travis.yml | 20 ++- .travis/TravisCI-OSX-PHP | 2 +- .travis/{configure => configure.sh} | 43 +++--- README.md | 123 +++++++++++++++ Scripts/bootargs.sh | 15 +- Scripts/bootstrap.sh | 3 +- Scripts/composer.sh | 28 ++-- Scripts/config_app_database.sh | 40 ++++- Scripts/config_etc_pass.sh | 5 +- Scripts/cp_bkp_old.sh | 3 +- Scripts/shell_prompt.sh | 5 +- app/Config/boot_profile.cms.php | 26 ++++ app/Config/bootstrap.php | 26 +--- app/Config/database.php.old | 79 ---------- app/Controller/AppController.php | 7 +- app/Controller/Component/MyFlashComponent.php | 11 +- app/View/Errors/missing_connection.ctp | 11 ++ app/View/Errors/missing_datasource_config.ctp | 11 ++ app/View/Helper/InfoHelper.php | 12 +- app/phpunit.xml.dist | 4 +- app/webroot/php_cms | 2 +- app/webroot/test.php | 3 + bootstrap_phpunit.php | 3 + composer.lock | 10 +- configure.sh | 17 ++- lib/Cake/Model/Datasource/Database/Mysql.php | 4 + .../Model/Datasource/Database/Postgres.php | 1 + lib/Cake/Model/Datasource/Database/Sqlite.php | 4 + migrate-database.sh | 142 +++++++----------- start-cake.sh | 2 +- test-cake.sh | 33 ++-- 32 files changed, 403 insertions(+), 295 deletions(-) rename .travis/{configure => configure.sh} (71%) create mode 100644 app/Config/boot_profile.cms.php delete mode 100644 app/Config/database.php.old create mode 100644 app/View/Errors/missing_connection.ctp create mode 100644 app/View/Errors/missing_datasource_config.ctp diff --git a/.gitignore b/.gitignore index e0e21bceb..98ef9fed6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # User specific & automatically generated files # ################################################# -/app/Config/database.php +/app/Config/database.php* /app/tmp /lib/Cake/Console/Templates/skel/tmp/ /plugins @@ -10,6 +10,7 @@ /tags *.mo /bin/composer.phar +/app/Config/identities.sql* # IDE and editor specific files # ################################# diff --git a/.travis.yml b/.travis.yml index e6ef152b6..375a88b3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,13 @@ cache: - $HOME/.composer/cache/files env: matrix: - - DB=mysql + - DB=Mysql global: + - TEST_MYSQL_SERVICE_HOST=127.0.0.1 + - TEST_MYSQL_SERVICE_PORT=3306 + - TEST_DATABASE_NAME=cakephp_test + - TEST_DATABASE_USER=root + - TEST_DATABASE_PASSWORD= - PHPUNIT=4 - PHPCS=3 - COLLECT_COVERAGE=true @@ -22,7 +27,7 @@ addons: project: name: "b23prodtm/myphpcms" notification_email: b23prodtm@users.sourceforge.net - build_command_prepend: .travis/configure + build_command_prepend: .travis/configure.sh build_command: if [ '${PHPCS}' != '1' ]; then ./lib/Cake/Console/cake test core AllTests --stderr; else ./app/vendor/bin/phpcs -p --extensions=php --standard=CakePHP ./lib/Cake; fi; branch_pattern: development services: @@ -36,11 +41,11 @@ matrix: include: - os: linux php: 5.6 - env: DB=pgsql + env: DB=Pgsql - os: linux php: 5.6 - env: DB=sqlite + env: DB=Sqlite - os: linux php: 5.6 @@ -81,13 +86,16 @@ install: # Local Test (osx configuration and mysql engine) : # $ ./test-cake.sh --travis before_script: - - .travis/configure + # remote servers CI doesn't need a root password import (-i) but the socket => -y + - ./configure.sh "-c" "-h" "-p" "pass" "-s" "word" "--mig-database" "-y" + - .travis/configure.sh script: + # tests with phpunit - ./test-cake.sh after_script: - - if [[ "$COLLECT_COVERAGE" == "true" ]]; then travis_retry php app/vendor/bin/coveralls -v ; fi + - if [[ "$COLLECT_COVERAGE" == "true" ]]; then travis_retry php app/vendor/bin/php-coveralls -v -r ./app/; fi # Openshift webhook notifies that a new build version is available # $OC_SECRET is obtained from an Openshift Console and set secret environment variable diff --git a/.travis/TravisCI-OSX-PHP b/.travis/TravisCI-OSX-PHP index 9a9274911..c7500f700 160000 --- a/.travis/TravisCI-OSX-PHP +++ b/.travis/TravisCI-OSX-PHP @@ -1 +1 @@ -Subproject commit 9a9274911732915d480372786216a81020a72e63 +Subproject commit c7500f7004b5161edda8b452a5e5b18a6abd536a diff --git a/.travis/configure b/.travis/configure.sh similarity index 71% rename from .travis/configure rename to .travis/configure.sh index 876795a93..0defb40d7 100755 --- a/.travis/configure +++ b/.travis/configure.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -source configure.sh "-c" "-d" "-y" "-h" "-p" "pass" "-s" "word" echo -e " Set of default environment ========================== @@ -9,25 +8,29 @@ echo -e " Documented VARIABLES TRAVIS_OS_NAME: os: ['osx','linux'] in .travis.yml TRAVIS_PHP_VERSION : php: in .travis.yml - DB=['mysql', 'pgsql', 'sqlite'] + DB=['Mysql', 'Pgsql', 'Sqlite'] optional environment VARIABLES ADDITIONAL_PHP_INI='path to a php.ini settings file' ========================== "; -php bin/composer.phar install --dev --no-interaction +php bin/composer.phar install --no-interaction if [ ! -z "${ADDITIONAL_PHP_INI}" ]; then /usr/bin/env bash .travis/TravisCI-OSX-PHP/build/custom_php_ini.sh; fi mkdir -p build/logs -echo "Database Unit Tests... DB=${DB}" -if [[ ("${TRAVIS_OS_NAME}" == "linux") && (${TRAVIS_PHP_VERSION:0:3} == "7.2") ]] ; then pear config-set preferred_state snapshot && yes "" | pecl install mcrypt ; fi -sudo locale-gen de_DE -sudo locale-gen es_ES -if [[ ${DB} == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi -if [[ ${DB} == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test2;'; fi -if [[ ${DB} == 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test3;'; fi -if [[ ${DB} == 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi -if [[ ${DB} == 'pgsql' ]]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi -if [[ ${DB} == 'pgsql' ]]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi +echo -e "Database Unit Tests... DB=${DB}" +if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then + if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]]; then + pear config-set preferred_state snapshot && yes "" | pecl install mcrypt ; + fi + sudo locale-gen de_DE + sudo locale-gen es_ES +fi +if [[ ${DB} == 'Mysql' ]]; then mysql -e 'CREATE DATABASE IF NOT EXISTS cakephp_test;' -u $TEST_DATABASE_USER --password=$TEST_DATABASE_PASSWORD; fi +if [[ ${DB} == 'Mysql' ]]; then mysql -e 'CREATE DATABASE IF NOT EXISTS cakephp_test2;' -u $TEST_DATABASE_USER --password=$TEST_DATABASE_PASSWORD; fi +if [[ ${DB} == 'Mysql' ]]; then mysql -e 'CREATE DATABASE IF NOT EXISTS cakephp_test3;' -u $TEST_DATABASE_USER --password=$TEST_DATABASE_PASSWORD; fi +if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi +if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE SCHEMA test2;' -U postgres -d cakephp_test; fi +if [[ ${DB} == 'Pgsql' ]]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi chmod -R 777 ./app/tmp if [[ ("${TRAVIS_OS_NAME}" == "linux") && (${TRAVIS_PHP_VERSION:0:3} == "5.3") ]] ; then pecl install timezonedb ; fi if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then @@ -39,14 +42,16 @@ if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then fi set +H echo " array( + 'Mysql' => array( 'datasource' => 'Database/Mysql', 'host' => '127.0.0.1', - 'login' => 'root' + 'login' => 'root', + 'password' => '${SQL_PASSWORD}' ), - 'pgsql' => array( + 'Pgsql' => array( 'datasource' => 'Database/Postgres', 'host' => '127.0.0.1', 'login' => 'postgres', @@ -58,7 +63,7 @@ echo " 'test3' ) ), - 'sqlite' => array( + 'Sqlite' => array( 'datasource' => 'Database/Sqlite', 'database' => array( 'default' => ':memory:', @@ -101,7 +106,7 @@ echo " '' ); public function __construct() { - \$db = 'mysql'; + \$db = 'Mysql'; if (!empty(\$_SERVER['DB'])) { \$db = \$_SERVER['DB']; } @@ -117,4 +122,4 @@ echo " app/Config/database.php - echo "Unit Test was set up in app/Config/database.php" + echo -e "{green}Unit Test was set up in app/Config/database.php{nc}" diff --git a/README.md b/README.md index 12e13d44c..dd595aec2 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ - [CakePHP Sample App on OpenShift](#cakephp-sample-app-on-openshift) + [Source repository layout](#source-repository-layout) + [Compatibility](#compatibility) + + [Local Built-in Server](#local-built-in-server) + + [PHP Unit Test](#php-unit-test) + + [Common Issues](#common-issues) + [License](#license) @@ -41,6 +44,126 @@ However, if these files exist they will affect the behavior of the build process This repository is compatible with PHP 5.6 and higher, excluding any alpha or beta versions. +### Local built-in server +>for local test only + +Open a Terminal window: + + ./start_cake.sh + +>Ctrl-click the URLs to open them in the browser. +### PHP Unit Test + +Open a Terminal window: + + ./test_cake.sh -p + +See [below](#common-issues) to allow access on the built-in local server. + +### Common Issues + +1. How to fix the following error? + +Index page displays: + + errno : 1146 + sqlstate : 42S02 + error : Table 'phpcms.info' doesn't exist + +Try the following to migrate (update) all database tables, answer 'y' when prompted: + + ./migrate-database.sh -u + +2. ACCESS DENIED to user appears with other information complaining about database connection, what does that mean ? + +You probably have modified user privileges on your server: + + mysql -u root + use mysql; + grant all on $TEST_DATABASE_NAME.* to '$TEST_DATABASE_USER'@'$TEST_MYSQL_SERVICE_HOST'; + exit + ./configure.sh -c + +This will reset the connection profile in ..etc/ properties file with the template. +More about environment variables are located in the remote pod (OpenShift) settings and locally in ./Scripts/bootargs.sh. + +3. ACCESS DENIED for root@'127.0.0.1' appears with other information complaining about database connection, what does that mean ? + +This looks like a first installation of mysql. You have to secure or reset your mysql root access: + + sudo rm -rf /usr/local/var/mysql + mysqld --initialize + +[Note] A temporary password is generated for root@localhost. Now import identities. + + brew services restart mysql@5.7 + ./migrate-database.sh -Y -i + + +4. My mysql server's upgraded to another version, what should I do ? + +Upgrade your phpcms database within a (secure)shell: + + mysql_upgrade -u root --password= + +4. I've made changes to mysql database tables, I've made changes to Config/Schema/myschema.php, as Config/database.php defines it, what should I do ? + +Migrate all your tables: + + ./migrate-database.sh -u + +Answer 'y' when prompted. + +5. How to fix up 'Database connection "Mysql" is missing, or could not be created' ? + +Check your environment variable (./Scripts/bootargs.sh or Docker/Pod settings) + + TEST_DATABASE_NAME=cakephp_test + +Log in with authorized privileges from a shell prompt: + + mysql -u root --password= cakephp_test + +6. How to fix up ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) ? + +Run the socket fixup script with arguments: + + ./migrate-database.sh -y + brew services restart mysql@5.7 + +7. I'm testing with ./start_cake.sh and I cannot add any new post on Updates section, what should I do ? + +With the CLI, you may ctrl-X ctrl-C to exit server and migrate your database: + + ./migrate-database.sh -U + ./start_cake.sh + +Answer 'y' when prompted. + +8. I cannot upload any picture, why ? + +The Mysql.php Datasource must define binary and mediumbinary storage types. Please check the file __lib/Cake/Model/Datasource/Mysql.php__, if you experienced the following error: + + errno : 1054 + sqlstate : 42S22 + error : Unknown column 'image' in 'field list' + +Add the *__mediumbinary__* storage: + +>public $columns = array(...) + + 'mediumbinary' => array('name' => 'mediumblob'), + +>public function column($real){...}, at line 814: + + if (strpos($col, 'mediumblob') !== false || $col === 'mediumbinary') { + return 'mediumbinary'; + } + +Update database schema: + + ./migrate-database.sh -U + ### License Copyright 2016 b23production GNU diff --git a/Scripts/bootargs.sh b/Scripts/bootargs.sh index 639625d0f..d0dacf9d0 100755 --- a/Scripts/bootargs.sh +++ b/Scripts/bootargs.sh @@ -8,13 +8,20 @@ orange="\033[0;33m" cyan="\033[0;36m" #; Host name (unix) 'localhost' generally replaces '127.0.0.1' (macOS). export DATABASE_ENGINE="Mysql" -export DATABASE_SERVICE_NAME="mysql" +export DATABASE_SERVICE_NAME="MYSQL" +export MYSQL_SERVICE_HOST="127.0.0.1" +#;export MYSQL_SERVICE_HOST="localhost" +export MYSQL_SERVICE_PORT="3306" +export DATABASE_NAME="phpcms" +export DATABASE_USER="test" +export DATABASE_PASSWORD="mypassword" +#. Test configuration ?test=1 export TEST_MYSQL_SERVICE_HOST="127.0.0.1" #;export TEST_MYSQL_SERVICE_HOST="localhost" export TEST_MYSQL_SERVICE_PORT="3306" -export TEST_DATABASE_NAME="phpcms" -export TEST_DATABASE_USER="test" -export TEST_DATABASE_PASSWORD="mypassword" +export TEST_DATABASE_NAME="cakephp_test" +export TEST_DATABASE_USER="root" +export TEST_DATABASE_PASSWORD=${SQL_PASSWORD} export FTP_SERVICE_HOST="localhost" export FTP_SERVICE_USER="test" export FTP_SERVICE_PASSWORD="mypassword" diff --git a/Scripts/bootstrap.sh b/Scripts/bootstrap.sh index 1c58e0939..19a7e7960 100755 --- a/Scripts/bootstrap.sh +++ b/Scripts/bootstrap.sh @@ -23,7 +23,7 @@ source $hash echo -e "${nc}Password ${green}$GET_HASH_PASSWORD${nc}" #; Install PHPUnit, performs unit tests #; The website must pass health checks in order to be deployed -phpunit="app/vendor/bin/phpunit" +phpunit="./app/Vendor/bin/phpunit" if [ ! -f $phpunit ]; then if [ ! -f bin/composer.phar ]; then source ./Scripts/composer.sh @@ -33,3 +33,4 @@ else echo -e "PHPUnit ${green}[OK]${nc}" fi echo `$phpunit --version` +source ./Scripts/config_app_database.sh diff --git a/Scripts/composer.sh b/Scripts/composer.sh index 5b32263ad..8ea1dff9a 100755 --- a/Scripts/composer.sh +++ b/Scripts/composer.sh @@ -13,25 +13,19 @@ cyan="\033[0;36m" composer="bin/composer.phar" if [ ! -f $composer ]; then echo -e "Composer setup...\n" - EXPECTED_SIGNATURE="$(curl -f https://composer.github.io/installer.sig)" - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")" - - if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ] - then - >&2 echo 'ERROR: Invalid installer signature' - rm composer-setup.php - exit 1 - fi - - php composer-setup.php --quiet --install-dir=bin - rm composer-setup.php + mkdir -p bin + cd bin + curl -sS https://getcomposer.org/installer | php + cd .. else echo -e "Composer ${green}[OK]${nc}" fi -echo `bin/composer.phar --version` +php bin/composer.phar --version echo -e "\n - If you see the message ${red}SHA1 signature could not be verified: broken signature${nc}\r - Do ${cyan}rm bin/composer.phar${nc} please, and again ${cyan}./Scripts/composer.sh${nc}.\r\n" + //// FAQ: + 1. When ${orange}SHA1 signature could not be verified: broken signature${nc} appears on terminal :\r + The composer binary wasn't downloaded on this machine or it must be updated : + Please copy and run : + ${cyan}rm bin/composer.phar && ./Scripts/composer.sh${nc}\n" #; update plugins and dependencies -echo `bin/composer.phar update --with-dependencies` +php bin/composer.phar update --with-dependencies --apcu-autoloader diff --git a/Scripts/config_app_database.sh b/Scripts/config_app_database.sh index cc34559b9..a1db43235 100755 --- a/Scripts/config_app_database.sh +++ b/Scripts/config_app_database.sh @@ -1,7 +1,35 @@ #!/bin/bash -dbfile=$1 -wd="app/Config" -source ./Scripts/cp_bkp_old.sh $wd $dbfile "database.php" -#; symlink mysql socket with php -sudo mkdir -p /var/mysql -if [ -h /var/mysql/mysql.sock ]; then ls -al /var/mysql/mysql.sock; else sudo ln -vs /tmp/mysql.sock /var/mysql/mysql.sock; fi; +sqlversion="5.7" +if [ ! $(which mysql) > /dev/null ]; then + echo -e "Missing MySQL ${sqlversion} database service." + brew outdated mysql@${sqlversion} | brew upgrade + echo -e "Installing with Homebrew..." + brew install mysql@${sqlversion} + echo -e "Starting the service thread..." + brew services start mysql@${sqlversion} + echo -e "Performing some checks..." + mysql_upgrade -u root & +else + mysql --version +fi +while [[ "$#" > 0 ]]; do case $1 in + *.php) + dbfile=$1 + wd="app/Config" + source ./Scripts/cp_bkp_old.sh $wd $dbfile "database.php" + ;; + -[yY]*) + #; symlink mysql socket with php + echo "Please allow the super-user to link mysql socket to php ..." + sudo mkdir -p /var/mysql + if [ -h /var/mysql/mysql.sock ]; then + ls -al /var/mysql/mysql.sock + else + sudo ln -vs /tmp/mysql.sock /var/mysql/mysql.sock + fi;; + *) + ;; +esac; shift; done +if [ ! -h /var/mysql/mysql.sock ]; then + echo -e "${orange}Warning:${nc}/var/mysql/mysql.sock symlink not found." +fi diff --git a/Scripts/config_etc_pass.sh b/Scripts/config_etc_pass.sh index d45ce3a66..fd46987f4 100755 --- a/Scripts/config_etc_pass.sh +++ b/Scripts/config_etc_pass.sh @@ -28,11 +28,8 @@ if [ -z $pass ]; then while true; do done; fi # read salt if not set -if [ -z $salt ]; then while true; do - while [ "$salt" == "" ] - do +if [ -z $salt ]; then while [ "$salt" == "" ]; do read -p "Please enter the salt word :" salt - done done; fi # read filename if not set if [ -z $hash_file ]; then diff --git a/Scripts/cp_bkp_old.sh b/Scripts/cp_bkp_old.sh index eb77269fa..da2e58752 100755 --- a/Scripts/cp_bkp_old.sh +++ b/Scripts/cp_bkp_old.sh @@ -1,5 +1,6 @@ #!/bin/bash set -e +if [[ "$#" < 3 ]]; then echo "Usage : ./Scripts/cp_bkp_old.sh "; exit 1; fi wd=$1 src=$2 dst=$3 @@ -18,4 +19,4 @@ if [[ ( -f $dst ) && ( -f $src ) && ( $(which md5) > /dev/null ) ]]; then fi cp -v $src $dst cd $pwd -echo -e "Okay, just run the shell script. Please, review the files.\n" +echo -e "${src} copied. Please, review the files.\n" diff --git a/Scripts/shell_prompt.sh b/Scripts/shell_prompt.sh index 044cb3f39..14951e5fc 100755 --- a/Scripts/shell_prompt.sh +++ b/Scripts/shell_prompt.sh @@ -2,15 +2,14 @@ set -e script=$1 title=$2 -while true -do +while true; do # (1) prompt user, and read command line argument if no 3rd arg echo -e "${cyan}Run ${title} ?...\n${nc}" answer=$3 case $answer in -[yY]* ) answer="Y";; - -[nN]* ) break;; + -[nN]* ) answer="N";; * ) read -p "Do ${script} now (Y/N) ? " answer;; diff --git a/app/Config/boot_profile.cms.php b/app/Config/boot_profile.cms.php new file mode 100644 index 000000000..f182db770 --- /dev/null +++ b/app/Config/boot_profile.cms.php @@ -0,0 +1,26 @@ + array('bootstrap' => true))); + +/*var_dump(App::path('Cms'));*/ +/* -- PHP AUTOLOAD + Load Composer autoload.*/ +require APP . 'Vendor' . DS . 'autoload.php'; +/* Remove and re-prepend CakePHP's autoloader as Composer thinks it is the + most important. + See: http://goo.gl/kKVJO7 */ +spl_autoload_unregister(array('App', 'load')); +spl_autoload_register(array('App', 'load'), true, true); +/* PHP AUTOLOAD (app/Vendor/autoload.php installed from composer) +It is recommended to use only one extension for all classes. +PHP (more exactly spl_autoload) does the rest for you +and is even quicker than a semantically equal self-defined autoload function like this one +*/ +App::build(array('Cms' => array(WWW_ROOT . 'php_cms' . DS . 'e13' . DS . 'include' . DS)), App::REGISTER); diff --git a/app/Config/bootstrap.php b/app/Config/bootstrap.php index 499a6e90b..31ce16404 100755 --- a/app/Config/bootstrap.php +++ b/app/Config/bootstrap.php @@ -110,27 +110,5 @@ 'file' => 'error', )); -/** - * Load DebugKit plugin - */ -CakePlugin::load('DebugKit', ['bootstrap' => true, 'routes' => true]); - -/** - * Load Markdown Plugin - */ -CakePlugin::load(array('Markdown' => array('bootstrap' => true))); - -/*var_dump(App::path('Cms'));*/ -/* -- PHP AUTOLOAD */ -// Load Composer autoload. -require APP . 'Vendor/autoload.php';// Remove and re-prepend CakePHP's autoloader as Composer thinks it is the -// most important. -// See: http://goo.gl/kKVJO7 -spl_autoload_unregister(array('App', 'load')); -spl_autoload_register(array('App', 'load'), true, true); -/* PHP AUTOLOAD (app/Vendor/autoload.php installed from composer) -It is recommended to use only one extension for all classes. -PHP (more exactly spl_autoload) does the rest for you -and is even quicker than a semantically equal self-defined autoload function like this one -*/ -App::build(array('Cms' => array(WWW_ROOT . 'php_cms' . DS . 'e13' . DS . 'include' . DS)), App::REGISTER); +/** PHP autoloader shall detect applcation plugins from this profile */ +include_once APP . 'Config' . DS . 'boot_profile.cms.php'; diff --git a/app/Config/database.php.old b/app/Config/database.php.old deleted file mode 100644 index cadefe8eb..000000000 --- a/app/Config/database.php.old +++ /dev/null @@ -1,79 +0,0 @@ - array( - 'datasource' => 'Database/Mysql', - 'host' => '127.0.0.1', - 'login' => 'root' - ), - 'pgsql' => array( - 'datasource' => 'Database/Postgres', - 'host' => '127.0.0.1', - 'login' => 'postgres', - 'database' => 'cakephp_test', - 'schema' => array( - 'default' => 'public', - 'test' => 'public', - 'test2' => 'test2', - 'test_database_three' => 'test3' - ) - ), - 'sqlite' => array( - 'datasource' => 'Database/Sqlite', - 'database' => array( - 'default' => ':memory:', - 'test' => ':memory:', - 'test2' => '/tmp/cakephp_test2.db', - 'test_database_three' => '/tmp/cakephp_test3.db' - ), - ) - ); - public $default = array( - 'persistent' => false, - 'host' => '', - 'login' => '', - 'password' => '', - 'database' => 'cakephp_test', - 'prefix' => '' - ); - public $test = array( - 'persistent' => false, - 'host' => '', - 'login' => '', - 'password' => '', - 'database' => 'cakephp_test', - 'prefix' => '' - ); - public $test2 = array( - 'persistent' => false, - 'host' => '', - 'login' => '', - 'password' => '', - 'database' => 'cakephp_test2', - 'prefix' => '' - ); - public $test_database_three = array( - 'persistent' => false, - 'host' => '', - 'login' => '', - 'password' => '', - 'database' => 'cakephp_test3', - 'prefix' => '' - ); - public function __construct() { - $db = 'mysql'; - if (!empty($_SERVER['DB'])) { - $db = $_SERVER['DB']; - } - foreach (array('default', 'test', 'test2', 'test_database_three') as $source) { - $config = array_merge($this->{$source}, $this->identities[$db]); - if (is_array($config['database'])) { - $config['database'] = $config['database'][$source]; - } - if (!empty($config['schema']) && is_array($config['schema'])) { - $config['schema'] = $config['schema'][$source]; - } - $this->{$source} = $config; - } - } - } diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 97fe47813..5c80fcf9b 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -20,11 +20,6 @@ * @license https://opensource.org/licenses/mit-license.php MIT License */ App::uses('Controller', 'Controller'); -/*App::import('file', 'Index', - array('file' => - WWW_ROOT . DS .'php_cms' . DS . 'e13' . DS . 'include' . DS . 'php_index.class.inc.php' - ) -);*/ App::uses('Index', 'Cms'); /** @@ -45,7 +40,7 @@ class AppController extends Controller { 'Flash' => array( 'className' => 'MyFlash')); public $helpers = array('Markdown.Markdown', 'Flash'); - protected var $_r; + protected $_r; public function __construct($request = null, $response = null) { parent::__construct($request, $response); diff --git a/app/Controller/Component/MyFlashComponent.php b/app/Controller/Component/MyFlashComponent.php index 42f498ad7..d02e30b14 100644 --- a/app/Controller/Component/MyFlashComponent.php +++ b/app/Controller/Component/MyFlashComponent.php @@ -8,6 +8,7 @@ /** * CakePHP MyFlashComponent * @author wwwb23prodtminfo + * Flash is a message displayed with emphasized text */ App::uses('FlashComponent', 'Controller/Component'); @@ -16,24 +17,24 @@ class MyFlashComponent extends FlashComponent { public $components = array(); - public function initialize($controller) { + public function initialize(Controller $controller) { parent::initialize($controller); } - public function startup($controller) { + public function startup(Controller $controller) { parent::startup($controller); } - public function beforeRender($controller) { + public function beforeRender(Controller $controller) { parent::beforeRender($controller); } - public function shutDown($controller) { + public function shutDown(Controller $controller) { parent::shutdown($controller); } - public function beforeRedirect($controller, $url, $status = null, $exit = true) { + public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) { parent::beforeRedirect($controller, $url, $status, $exit); } diff --git a/app/View/Errors/missing_connection.ctp b/app/View/Errors/missing_connection.ctp new file mode 100644 index 000000000..98c4bf371 --- /dev/null +++ b/app/View/Errors/missing_connection.ctp @@ -0,0 +1,11 @@ +

+ : + +

+

: database.cms.php, (./start_cake.sh) bootargs.sh +:

./migrate-database.sh -Y -i
+

+ 0): + echo $this->element('exception_stack_trace'); +endif; diff --git a/app/View/Errors/missing_datasource_config.ctp b/app/View/Errors/missing_datasource_config.ctp new file mode 100644 index 000000000..8f7e80be6 --- /dev/null +++ b/app/View/Errors/missing_datasource_config.ctp @@ -0,0 +1,11 @@ +

+ : + +

+

: database.cms.php +:

./configure.sh -d -Y
+

+ 0): + echo $this->element('exception_stack_trace'); +endif; diff --git a/app/View/Helper/InfoHelper.php b/app/View/Helper/InfoHelper.php index 4f0702eae..bae467d97 100644 --- a/app/View/Helper/InfoHelper.php +++ b/app/View/Helper/InfoHelper.php @@ -1,21 +1,23 @@ $index, "countPerPage" => "5", "Markdown" => true)) { + public function __construct(View $view, $settings = array("index" => null, "countPerPage" => "5", "Markdown" => true)) { parent::__construct($view, $settings); - $this->r = $index; + $this->r = $settings["index"]; if(array_key_exists("countPerPage", $settings)) { $this->pageCount = $settings["countPerPage"]; } diff --git a/app/phpunit.xml.dist b/app/phpunit.xml.dist index c8c2b87f8..b7a2d9adc 100644 --- a/app/phpunit.xml.dist +++ b/app/phpunit.xml.dist @@ -2,13 +2,13 @@ 0 ]]; do case $1 in -[cC]*|--const) - source ./Scripts/shell_prompt.sh "./Scripts/config_etc_const.sh" "${cyan}Step 1. Overwrite constantes.properties\n${nc}" '-Y';; + source ./Scripts/shell_prompt.sh "./Scripts/config_etc_const.sh" "${cyan}Step 1. Overwrite constantes.properties\n${nc}" '-Y' + ;; -[hH]*|--hash) #; get hash password - source ./Scripts/shell_prompt.sh "./Scripts/config_etc_pass.sh ${args}" "${cyan}Step 2. Get a hashed password with encryption, PHP encrypts.\n${nc}" '-Y';; + source ./Scripts/shell_prompt.sh "./Scripts/config_etc_pass.sh ${args}" "${cyan}Step 2. Get a hashed password with encryption, PHP encrypts.\n${nc}" '-Y' + ;; -[dD]*|--mig-database) #; Know-How : In Openshift 3, configure a CakePhp-Mysql-persistent docker image. Set automatic deployment with _100%_ unavailability #; If it starts a build, it automatically scales deployments down to zero, and deploys and scales up when it's finished to build. #; Be sure that lib/Cake/Console/cake test app and Health checks should return gracefullly, or the pods get terminated after a short time. #; [[-d|--mig-database] [-y]] argument fixes up : Error: Database connection "Mysql" is missing, or could not be created. - source ./Scripts/shell_prompt.sh "migrate-database.sh ${2}" "${cyan}Step 3. Migrate database\n${nc}" '-Y' - shift;; + shift + source ./Scripts/shell_prompt.sh "migrate-database.sh $*" "${cyan}Step 3. Migrate database\n${nc}" '-Y' + ;; -[sS]*|-[pP]*|-[fF]*) shift;; - -[hH]*|--help ) - echo "./configure.sh [-c|--const] [[-d|--mig-database] [-y]] [-h|--hash [-p password -s salt [-f filename]]] + --help ) + echo "./configure.sh [-c|--const] [-h|--hash [-p password -s salt [-f filename]]] [[-d|--mig-database] [-y]] -c Reset to app/webroot/php_cms/etc/constantes-template.properties -h Reset administrator password hash -p -s [-f ] diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index 7a13c3108..bb07bea7e 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -131,6 +131,7 @@ class Mysql extends DboSource { 'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'), 'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'), 'binary' => array('name' => 'blob'), + 'mediumbinary' => array('name' => 'mediumblob'), 'boolean' => array('name' => 'tinyint', 'limit' => '1') ); @@ -810,6 +811,9 @@ public function column($real) { if (strpos($col, 'blob') !== false || $col === 'binary') { return 'binary'; } + if (strpos($col, 'mediumblob') !== false || $col === 'mediumbinary') { + return 'mediumbinary'; + } if (strpos($col, 'float') !== false || strpos($col, 'double') !== false) { return 'float'; } diff --git a/lib/Cake/Model/Datasource/Database/Postgres.php b/lib/Cake/Model/Datasource/Database/Postgres.php index 2bf200fee..11497d454 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -69,6 +69,7 @@ class Postgres extends DboSource { 'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'), 'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'), 'binary' => array('name' => 'bytea'), + 'mediumbinary' => array('name' => 'bytea'), 'boolean' => array('name' => 'boolean'), 'number' => array('name' => 'numeric'), 'inet' => array('name' => 'inet'), diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index 2cf39c356..50b0afe33 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -81,6 +81,7 @@ class Sqlite extends DboSource { 'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'), 'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'), 'binary' => array('name' => 'blob'), + 'mediumbinary' => array('name' => 'mediumblob'), 'boolean' => array('name' => 'boolean') ); @@ -290,6 +291,9 @@ public function column($real) { if (in_array($col, array('blob', 'clob'))) { return 'binary'; } + if (in_array($col, array('mebiumblob', 'mediumclob'))) { + return 'mediumbinary'; + } if (strpos($col, 'numeric') !== false || strpos($col, 'decimal') !== false) { return 'decimal'; } diff --git a/migrate-database.sh b/migrate-database.sh index 9d6e4f0d0..18cc18398 100755 --- a/migrate-database.sh +++ b/migrate-database.sh @@ -18,84 +18,40 @@ set -e source ./Scripts/bootargs.sh echo -e " -${red} ///// MySQL HOWTO: connect to the database${nc} - - A MySQL@5.6 server (must match remote server version) - must be reachable locally. If it's the 1st time you use this connection, - Configure it as a service and log in with super or admin user shell:${green}mysql -u root${nc} - These SQL statements initializes the database, replaced with ${orange}environment variables${nc} : - - create database ${orange}${TEST_DATABASE_NAME}${nc}; - use mysql; - create user '${cyan}${TEST_DATABASE_USER}${nc}'@'${TEST_MYSQL_SERVICE_HOST}'; - alter user '${cyan}${TEST_DATABASE_USER}${nc}'@'${TEST_MYSQL_SERVICE_HOST}' identified by '${orange}${TEST_DATABASE_PASSWORD}${nc}'; - select * from user where user = '${cyan}${TEST_DATABASE_USER}${nc}'; - ${orange}grant all${nc} on ${TEST_DATABASE_NAME}.* to '${cyan}${TEST_DATABASE_USER}${nc}'@'${TEST_MYSQL_SERVICE_HOST}'; - -${nc} - The values of CakePHP DB VARIABLES available at ${cyan}app/Config/database.php${nc}. - Don't forget to grant all privileges. - Type in shell to login ${green}mysqld ${nc}local daemon as above should give the following results : -${orange} - mysql -u root - create database \$TEST_DATABASE_NAME; - use mysql; - create user '\$TEST_DATABASE_USER'@'\$TEST_MYSQL_SERVICE_HOST'; - ${green} - > Query OK, 0 row affected, ... - ${orange} - alter user '\$TEST_DATABASE_USER'@'127.0.0.1' identified by '\$TEST_DATABASE_PASSWORD'; - ${green} - > Query OK, 0 row affected, ... - ${orange} - grant all on \$TEST_DATABASE_NAME.* to '\$TEST_DATABASE_USER'@'\$TEST_MYSQL_SERVICE_HOST'; - ${green} - > Query OK, 0 row affected, ... - ${nc} - -${red} ///// FAQ${nc} : - - 1. - errno : 1146 - sqlstate : 42S02 - error : Table 'phpcms.info' doesn't exist - -Run again ${green}./migrate-database.sh${nc}, to create or update database tables. - - 2. -If ACCESS DENIED appears, please verify the user name and localhost values then -${cyan} - grant all on phpcms.* to this user as above. -${nc} - - 3. -${green}Whenever mysql server changes to another version${nc}, try an upgrade of phpcms database within a (secure)shell ${green}mysql_upgrade -u root${nc} - - 4. -${green}Make changes to SQL database structure (table-models)${nc}, by modifying Config/Schema/myschema.php, as Config/database.php defines it. -Run ${green}./migrate-database.sh${nc}, answer ${cyan}Y${nc}es when prompted, which may not display any ${red}SQLSTATE [error]${nc}. +${red} + ///// MySQL HOWTO: connect to the database${nc} + A MySQL server (must match remote server version) + must be reachable locally. If it's the 1st time you use this connection, + Configure it as a service and log in with super or admin user shell:${green}mysql -u root -p${nc} + See common issues in README.md file. + These SQL statements initializes the database, replaced with current ${orange}environment variables${nc} : " -sqlversion="5.7" -if [ ! $(which mysql) > /dev/null ]; then - echo -e "Missing MySQL ${sqlversion} database service." - brew outdated mysql@${sqlversion} | brew upgrade - echo -e "Installing with Homebrew..." - brew install mysql@${sqlversion} - echo -e "Starting the service thread..." - brew services start mysql@${sqlversion} - echo -e "Performing some checks..." - mysql_upgrade -u root & -fi +identities=app/Config/identities.sql +if [[ -f $identities ]]; then ./Scripts/cp_bkp_old.sh . $identities ${identities}.old; fi echo -e " -If the ${red}Error: 'Database connection \"Mysql\" is missing, or could not be created'${nc} - shows up, please check up your ${cyan}TEST_DATABASE_NAME=$TEST_DATABASE_NAME${nc} environment variable (set up is above in this shell script or in web node settings). - Log into the SQL shell ${green}mysql -u root${nc} and check if you can do : ${green}use $TEST_DATABASE_NAME${nc}. - Run the socket fixup script with arguments ${green}./migrate-database.sh -Y${nc} - ${green}brew services start mysql@${sqlversion}${nc}" -if [ ! -f /var/mysql/mysql.sock ]; then - echo -e "${orange}We must fix up : ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)${nc}" - echo -e "Run this script again with ${green}./migrate-database.sh -Y${nc}" -fi + create database if not exists ${DATABASE_NAME};\r + use mysql;\r + create user if not exists '${DATABASE_USER}'@'${MYSQL_SERVICE_HOST}';\r + alter user '${DATABASE_USER}'@'${MYSQL_SERVICE_HOST}' identified by '${DATABASE_PASSWORD}';\r + select * from user where user = '${DATABASE_USER}';\r + grant all on ${DATABASE_NAME}.* to '${DATABASE_USER}'@'${MYSQL_SERVICE_HOST}';\r + + create database if not exists ${TEST_DATABASE_NAME};\r + use mysql;\r + create user if not exists '${TEST_DATABASE_USER}'@'${TEST_MYSQL_SERVICE_HOST}';\r + alter user '${TEST_DATABASE_USER}'@'${TEST_MYSQL_SERVICE_HOST}' identified by '${TEST_DATABASE_PASSWORD}';\r + select * from user where user = '${TEST_DATABASE_USER}';\r + grant all on ${TEST_DATABASE_NAME}.* to '${TEST_DATABASE_USER}'@'${TEST_MYSQL_SERVICE_HOST}';\r +" > $identities +cat $identities +# Got passed args so we have saved them before $ source