From a4aac3336c4e67de00184509a8b5d49ad1869edd Mon Sep 17 00:00:00 2001 From: Tiana Rakoto Arimanana <5566338+b23prodtm@users.noreply.github.com> Date: Mon, 3 Dec 2018 01:16:34 +0100 Subject: [PATCH] Hotfix/s2i openshift (#38) * database configuration user passwords * autoload.php * post-commit hook issue lib/cake/cache/Engine/FileEngine Cache application directory Cache long persist file perms * Markdown-plugin composer * Merge branch 'feature/b23prodtm-markdown-patch-1' into openshift-publish * composer * Shell Test Script * --openshift arg * How to fix up 'Database connection "Mysql" is missing, or could not be created' ? * ERROR 1044 (42000) at line 1: Access denied for user 'test'@'localhost' to database 'cakephp_test2' * migrate script and socket * dollar-star shell * openshift: no mysql identities to import * usage of blank password * 'MysqlCms' in 'app/Model/Datasource/Database' * coverity_scan branch --- .DS_Store | Bin 6148 -> 12292 bytes .gitignore | 20 +- .travis.yml | 31 +-- .travis/configure.sh | 45 ++-- README.md | 119 +++++++--- Scripts/bootargs.sh | 35 ++- Scripts/bootstrap.sh | 24 +- Scripts/composer.sh | 2 +- Scripts/config_app_database.sh | 8 +- Scripts/config_etc_pass.sh | 3 + Scripts/cp_bkp_old.sh | 2 +- Scripts/lib/parsing.sh | 47 ++++ Scripts/lib/shell_prompt.sh | 32 +++ Scripts/shell_prompt.sh | 28 --- app/Config/Schema/myschema.php | 2 +- app/Config/Schema/schema.php | 2 +- app/Config/boot_profile.cms.php | 4 +- app/Config/bootstrap.php | 14 ++ app/Config/database.cms.php | 33 ++- app/Model/Datasource/Database/MysqlCms.php | 32 +++ app/Model/Datasource/Database/PostgresCms.php | 11 + app/Model/Datasource/Database/SqliteCms.php | 32 +++ app/Vendor/autoload.php | 7 - app/View/E14/admin_cat.ctp | 11 +- app/tmp/cache/long/empty | 0 composer.json | 8 +- composer.lock | 64 +++--- configure.sh | 58 +++-- 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 | 212 +++++++++++------- start-cake.sh | 31 ++- test-cake.sh | 49 ++-- 34 files changed, 639 insertions(+), 336 deletions(-) create mode 100755 Scripts/lib/parsing.sh create mode 100755 Scripts/lib/shell_prompt.sh delete mode 100755 Scripts/shell_prompt.sh create mode 100644 app/Model/Datasource/Database/MysqlCms.php create mode 100644 app/Model/Datasource/Database/PostgresCms.php create mode 100644 app/Model/Datasource/Database/SqliteCms.php delete mode 100644 app/Vendor/autoload.php create mode 100755 app/tmp/cache/long/empty diff --git a/.DS_Store b/.DS_Store index 4fb5f13d732cdf6a1888838fd4d90f558d347917..de280936a90dc8e721472073a9f85050d5e8cf20 100644 GIT binary patch literal 12292 zcmeHL&2Jk;6n`%XV5bRPnx+k3l}Rp@npy#ZS|kw0q@@9&ggBxJO)!gT`SU}g>J8i7H;AYc$M2p9wm0{;vI@XnSk zH{!jYuA0#xU=a9UA|Rg+1$0SEnjWQ8JvuO`5&(1pV%5N_kAKjD6o8gAJxVDgXq=jY zrlzb*4A!*+r{-8MY5k*=rsl*dGW_VstSc1Or3V+3I&mqbW;6&G1cniiwfi{P)S}jE zFi^kW#L8uKK0a1vTFdFgEnVe*0KcQPZ~L{RS+y=69=`DMON)i;%iYDo z;k9c^i-qMEuXnrod@gT&otvF6zH)2RKK!`*;1jh=V*P-i>2!WFehNbEbK{%jyw;o{trPd)w2vzIOvs@9BSySt4@ z0`P_iL{tvi-j?r*u;PE@Z6)48BAKdnE~B^M)jl{CZQgG|=lrQa`Fb<*yzovV@@s4L zdh8`zef)OSIvcx@2!eGH`-v~Y?VT9-uO{B!YFHPDxbJ(NwU%6p-}9mvbjW6F+m0eT zYoq+(ZEw(EzDh1Y&fp2norrB#V5keP=sDSzfgKxtL5kly-sgYg__i%&*@A0ioT`q=qLJxe&Y$g!1H{C zm-$t`$+!4jexF?qc#j1iaF-vjJ|$zlQ}SFdd`kH1-}@l#x^KqbQr6 zthEd1AEL`9^^Q`iOfaZ&98{I#pt>Aax&^38o06tSDTM^>Z~r4;^!u{^E5f}0)zvYB mLBJqj5HJWB1PlTO0fT@+z#w1{FbEg~3<3rLgTTKPf!_f-Bi3U8 delta 345 zcmZokXfcprU|?W$DortDU=RQ@Ie-{MGjUEV6q~50D9Qqo2ZJa83asbkkW@Fe_fE>M>FDh0?&)2zih)56 z=w=2+pnt$X5K6d81{T{K&ohS^03e}Fk^lez diff --git a/.gitignore b/.gitignore index 98ef9fed6..d67ebe5d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,17 @@ # User specific & automatically generated files # ################################################# /app/Config/database.php* +/app/Config/database.sql* /app/tmp +/app/Vendor/ +!/app/Vendor/autoload.php +/app/webroot/e13/nbproject/private/ +/app/tmp/cache/ +/app/tmp/logs/ +/app/tmp/persistent/ +/app/tmp/sessions/ +/app/webroot/php-cms/e13/nbproject/private/ +!*empty /lib/Cake/Console/Templates/skel/tmp/ /plugins /vendor @@ -10,7 +20,6 @@ /tags *.mo /bin/composer.phar -/app/Config/identities.sql* # IDE and editor specific files # ################################# @@ -30,12 +39,3 @@ Icon? ehthumbs.db Thumbs.db /nbproject/private/ -/app/Vendor/ -!/app/Vendor/autoload.php -/app/webroot/e13/nbproject/private/ -/app/tmp/cache/ -/app/tmp/logs/ -/app/tmp/persistent/ -/app/tmp/sessions/ -/app/webroot/php-cms/e13/nbproject/private/ -!*empty diff --git a/.travis.yml b/.travis.yml index 48c28e477..6b96cf1ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,25 +7,19 @@ env: matrix: - 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 - # The next declaration is the encrypted OC_SECRET, created - # via the "travis encrypt" command using the project repo's public key - - secure: "O+HejqZgXZFf0eD3GdvUwL2dsJsW+5biztfWYKHNfzv5u9j6Nn8JSoLdIp+Bg6Kct6kCJebM7oWHCh1fhyEm3AluusmqKHN8VKwQuINEZKAxPRFGl3NKkEU/Y95tHR3JIubZbZ0oZYmnl7z+YgVvM4LvmfvAwdpXzRt4SWOzGRWiL8uRaovOwW10HUB6qcO70Rn9XIHz4gUAoAEWQgSlJ4aNftu/lpuYs4P1r0+6fI/nfRRBMOogBQLEMqw6enPP+RrWx2pLwuxaQqChtk2td5PJdLiifW7C8SiAsljSgIRiaytAOgIs5KJsLGUdAPNXIMqUYFJ776J3L+ln8/nM/H8ARGB2P3smY5HM34/NrzUat2X/B6Uqg1F0Fs/794aomhaeqgh4b2MRI5srjQ/grNK61H1AftdR6JSLVjm6AUg743GQJF7sgNfK60n28EEZApAEzDS0v1PyU7U/HAZIalqWnttO0ycQyj2rf1XC++6BuTcRdmxx4dZoqZIn7xHzBQvi99ljv4JuwUgrNYXvcSEkXu6Y5GqMl2rtjxrdaGATpePuk1ju1kfB/7fQsR3ZZOaxULOSlQRcArsyseOtmEqQ1h5BVSmOGV+yoEboNm2FDZH/gD9ZZ7kTi+bk4bvHRZSD06JiDZ12W/JGsmU77phVIIWuUcXghEZf/WRjTe4=" + - COLLECT_COVERAGE=false + - WEBHOOK_URL=https://discordapp.com/api/webhooks/479745392880386058/YOO7Nnn1IFWUtXX0n0qAZYeMDeV-SLa0lSzjGpNnKGTzG-xA0T3dplVGzSM4ObKLeMWg # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created - # via the "travis encrypt" command using the project repo's public key - - secure: "4rmDT/vKTSi8AqI3afVUylayJ+SQbxblwlz/z81No4nLYWoy0dT61R/ZXq2Y29BE/HGEwx6r8Fl5RU6DxnmD7KhLC/3swHifzed690VDWyLii7cK8QkXVfLVVo8p+ozIwUrirnYFEkAcTfmkwJbmZN6DUuHJCl4x14NolR82VlJtFOVoWs63r+2NVJ5aM+63bkljkcW2U4xTt/8aOrCU/UapwqxC1GA0xPpwte6jPhzUjKXWbiknY+noUakM13x8SOkSRs3MTEf8J2va2T6DbVY3wy3x2Ytp4/KDwVNUrn/GKgBDRysP3jefO2d6XZJlb8OktJsrHdtWIZ+oYVwoy0PRV3vmdHs1NFUmYdQEe5UpiUKKyxWMsM+31to5ZUtJtn4kIlgzyo+xZu+LCgbOusJs33uPZODOON5fHcAoMp3AdAM0ResBfJdjzYEiewlcGYAcOoMX6DtopoJCoz+JxktdzXnjz89imNKMB2tjsRXuZMdE0WL3V2TSuOS5r8BwuuXXeul5vvE2EKHoIHgrP2nehz+q7dyC71m6jNrQX7x+xVg988vh0Fg8hyghLUzt9Myv4pvtQ/zQDbabKGtsakiHSvPTeHcb8mDhs62h5aIWUar8oXNuOWlk+hnyqZLmnbUPDcg54o567NursWYSWemAnPkPvSTfX0DQF1hDvSo=" + # via the "travis encrypt" command using the project repo's public key + - secure: "C39DQ1zYpSAOy33Sb8NP89o6k4HUnjHnQ+bQkgbo3WH7WtiN76dGeO9jm1DjMn5np6oKbDi41/fxonaTUIjb9YMksG2YB+NBDYXHyV1H7/xAeC6uTxwUObrLXh8aOUwiiuLPllMdtOLX8JSPxl1Ixc6KyeFywPiMvwuOe4QZW6sVG4sqhZC/UUycYKRSMaOthtuTDPYKjBLaDPiEzkUmdBIo9IhAsidEFAHj4jEmw9gBtac0B2x7GbvvoDivdH3KdNSoPt2SkD0RLX51Qf7AYeAV4fw65cuCp/Aat/uk55x3lN5g18Ww9khY/cFSwPC0JXGQnnJvdcDP2diZNkqE41Yc/Mw3xwfrvp3/v8js3VIBzsGINKiSdXZ/yXqI9iRzvzlfmXRHvd4sFXRzUpi8ZB4PXaboMndbNRoh4PcoRNFtXhyebQCEgZv2x3oiKXw38WT5cga03uMH4E5z5afS3n7NP1tsuiNWd499dJzAkW8OPeLDPqY3a/b5qLeZIK1bo23mvCjPtbm+B2g2QocKcd1oQ+XANCyuT3M/+AIypdMabGOSon2fDKrUUN+SqIX4FcYaHi1sG3qUp23870u9YcT4hK2LCKBcBPkFpxqEZLwdHbJmjHPo6uRyAKOD7r/k1DtIRqkcJ+5BpU4emo6rM9rdh5mWjLtK7vdY8Y/tvP8=" addons: coverity_scan: project: name: "b23prodtm/myphpcms" + description: "This PHP CMS is featuring well-known functionalities as cool as posting some web contents with pictures stored in a database. Developer Note : This is the Cake PHP cartridge repository. A submodule is included in app/webroot." notification_email: b23prodtm@users.sourceforge.net build_command_prepend: ./configure.sh "-c" "-h" "-p" "pass" "-s" "word" "--mig-database" "-y" && .travis/configure.sh build_command: ./test-cake.sh --cov | grep Test @@ -97,14 +91,7 @@ script: after_script: - if [[ ("${COLLECT_COVERAGE}" == "true") && ("${COVERITY_SCAN_BRANCH}" != 1) ]]; 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 -notifications: - email: false - webhooks: - urls: - - http://api.starter-us-west-1.openshift.com:443/oapi/v1/namespaces/e14/buildconfigs/cakephp-mysql-persistent/webhooks/$OC_SECRET/generic - - https://webhook-proxy-e14.a3c1.starter-us-west-1.openshiftapps.com/travis-ci/api.starter-us-west-1.openshift.com:443/e14/cakephp-mysql-persistent/webhooks/$OC_SECRET/generic - on_success: always - on_failure: never - on_start: never # default: always +after_success: + - wget https://raw.githubusercontent.com/k3rn31p4nic/travis-ci-discord-webhook/master/send.sh + - chmod +x send.sh + - ./send.sh success $WEBHOOK_URL diff --git a/.travis/configure.sh b/.travis/configure.sh index 0defb40d7..be3bef6da 100755 --- a/.travis/configure.sh +++ b/.travis/configure.sh @@ -2,18 +2,29 @@ echo -e " Set of default environment ========================== - Find exports for local development phase only in './Scripts/bootargs.sh') + Find exports for local development phase (testing) only in './Scripts/bootargs.sh') "; echo -e " -Documented VARIABLES - TRAVIS_OS_NAME: os: ['osx','linux'] in .travis.yml - TRAVIS_PHP_VERSION : php: in .travis.yml +Documented VARIABLES in .travis.yml + TRAVIS_OS_NAME: os: ['osx','linux'] + TRAVIS_PHP_VERSION : php: DB=['Mysql', 'Pgsql', 'Sqlite'] -optional environment VARIABLES +Required VARIABLES in .travis.yml or Pod environment + DATABASE_USER: + DATABASE_PASSWORD: + TEST_DATABASE_USER: + TEST_DATABASE_PASSWORD: + if [ DB='Mysql' ]; then + TEST_MYSQL_SERVICE_HOST: + else if [ DB='pgsql' ]; then + TEST_POSTGRES_SERVICE_HOST: + fi +optional environment VARIABLES in .travis.yml ADDITIONAL_PHP_INI='path to a php.ini settings file' ========================== "; +[ ! -z $TEST_DATABASE_USER ] && [ ! -z $TEST_DATABASE_PASSWORD ] && [[ (! -z $TEST_MYSQL_SERVICE_HOST) || (! -z $TEST_POSTGRES_SERVICE_HOST) ]] || echo "Missing VARIABLES. Please review your settings !" 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 @@ -25,9 +36,9 @@ if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then 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} == 'Mysql' ]]; then mysql -v -e 'CREATE DATABASE IF NOT EXISTS cakephp_test;' -u ${DATABASE_USER} --password=${DATABASE_PASSWORD}; fi +if [[ ${DB} == 'Mysql' ]]; then mysql -v -e 'CREATE DATABASE IF NOT EXISTS cakephp_test2;' -u ${DATABASE_USER} --password=${DATABASE_PASSWORD}; fi +if [[ ${DB} == 'Mysql' ]]; then mysql -v -e 'CREATE DATABASE IF NOT EXISTS cakephp_test3;' -u ${DATABASE_USER} --password=${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 @@ -46,15 +57,15 @@ echo " array( - 'datasource' => 'Database/Mysql', - 'host' => '127.0.0.1', - 'login' => 'root', - 'password' => '${SQL_PASSWORD}' + 'datasource' => 'Database/MysqlCms', + 'host' => '${TEST_MYSQL_SERVICE_HOST}', + 'login' => '${TEST_DATABASE_USER}', + 'password' => '${TEST_DATABASE_PASSWORD}' ), 'Pgsql' => array( - 'datasource' => 'Database/Postgres', - 'host' => '127.0.0.1', - 'login' => 'postgres', + 'datasource' => 'Database/PostgresCms', + 'host' => '${TEST_POSTGRES_SERVICE_HOST}', + 'login' => '${TEST_DATABASE_USER}', 'database' => 'cakephp_test', 'schema' => array( 'default' => 'public', @@ -64,7 +75,7 @@ echo " array( - 'datasource' => 'Database/Sqlite', + 'datasource' => 'Database/SqliteCms', 'database' => array( 'default' => ':memory:', 'test' => ':memory:', @@ -122,4 +133,4 @@ echo " app/Config/database.php - echo -e "{green}Unit Test was set up in app/Config/database.php{nc}" + echo -e "${green}Unit Test was set up in app/Config/database.php${nc}" diff --git a/README.md b/README.md index 9108911e6..6f0e2aba2 100644 --- a/README.md +++ b/README.md @@ -49,17 +49,49 @@ This repository is compatible with PHP 5.6 and higher, excluding any alpha or be Open a Terminal window: - ./start_cake.sh + ./start_cake.sh >Ctrl-click the URLs to open them in the browser. ### PHP Unit Test Open a Terminal window: - ./test_cake.sh -p + ./test-cake.sh -p= See [below](#common-issues) to allow access on the built-in local server. +### Server-side environment + +When deployment happens on server-side or is triggered by a git push event, 'source-to-image (s2i)', the httpd-server or pod needs proper environment variables to be set ready. Otherwise the scripts will fail with an error state, unable to connect to the database + +The following variables must be set up as server environment, provided by your **database administrator**: + + # Sqlite_cms, Postgres_cms + DATABASE_ENGINE:Mysql_cms + DATABASE_NAME:default + DATABASE_SERVICE_NAME:mysql + # a host alias or IP address + MYSQL_SERVICE_HOST:mysql + +>Note: Prefixed with *TEST_* they are used by the index.php?test=1 URLs and ./test-cake.sh (also in post git commit to test) + +The following additional variables must be set up as server secrets environment, provided by your database administrator: + + #(optional) + WEBHOOK_URL: + # Persistent connection credentials + DATABASE_USER: + DATABASE_PASSWORD: + # Just add TEST_DATABASE_USER and TEST_DATABASE_PASSWORD + TEST_DATABASE_USER: + TEST_DATABASE_PASSWORD: + # CakePHP generated + CAKEPHP_SECRET_TOKEN: + CAKEPHP_SECRET_SQLT: + CAKEPHP_SECURITY_CIPHER_SEED: + # Generated by ./configure.sh -h + GET_HASH_PASSWORD: + ### Common Issues 1. How to fix the following error? @@ -74,7 +106,7 @@ Try the following to migrate (update) all database tables, answer 'y' when promp ./migrate-database.sh -u -2. ACCESS DENIED to user appears with other information complaining about database connection, what does that mean ? +2. ACCESS DENIED appears with other information complaining about database connection, what does that mean ? You probably have modified user privileges on your server: @@ -87,7 +119,13 @@ You probably have modified user privileges on your server: 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 ? +>Note: + + ./configure.sh --mig-database -i -p -t + +to do a reset with environment root and user password. + +3. ACCESS DENIED for root@'127.0.0.1' or root@'localhost' 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: @@ -97,8 +135,8 @@ This looks like a first installation of mysql. You have to secure or reset your [Note] A temporary password is generated for root@localhost. Now import identities. brew services restart mysql@5.7 - ./migrate-database.sh -Y -i - + ./migrate-database.sh -y -i -p= + ./test-cake.sh -t= 4. My mysql server's upgraded to another version, what should I do ? @@ -116,18 +154,17 @@ 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), case-sensitive !: +Log in with root privileges should work: - TEST_DATABASE_NAME=cakephp_test - TEST_DATABASE_USER=test - TEST_DATABASE_PASSWORD= - TEST_DATABASE_SERVICE_NAME=Mysql - TEST_DATABASE_Mysql_HOST=localhost or mysql on OpenShift - TEST_DATABASE_Mysql_PORT=3306 + mysql -u root --password= cakephp_test -Log in with authorized privileges from a shell prompt: +Check your environment variable (./Scripts/bootargs.sh or Docker/Pod settings) - mysql -u root --password= cakephp_test + MYSQL_SERVICE_HOST=localhost + or + MYSQL_SERVICE_HOST=127.0.0.1 + +Use one or the other, and see which works for you. 6. How to fix up ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) ? @@ -147,25 +184,49 @@ 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: +The Mysql.php Datasource must define binary and mediumbinary storage types. Please look at the file __app/Model/Datasource/Mysql_cms.php__ if it exists and 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: +Add the *__mediumbinary__* storage, extending the original Datasource class: + +```columns['mediumbinary'] = array('name' => 'mediumblob'); + } + + /** + * Converts database-layer column types to basic types + * + * @param string $real Real database-layer column type (i.e. "varchar(255)") + * @return string Abstract column type (i.e. "string") + */ + public function column($real) { + $s = parent::column($real); + if($s === "text") { + $col = str_replace(')', '', $real); + $limit = $this->length($real); + if (strpos($col, '(') !== false) { + list($col, $vals) = explode('(', $col); + } + if (strpos($col, 'mediumblob') !== false || $col === 'mediumbinary') { + return 'mediumbinary'; + } + } + return $s; + } +} +?> +``` +Ensure it is set as DATABASE_ENGINE in __app/Config/database.cms.php__, __./Scripts/bootargs.sh__, __.travis.yml__ and update the database schema: ./migrate-database.sh -u diff --git a/Scripts/bootargs.sh b/Scripts/bootargs.sh index d0dacf9d0..0f2215f7c 100755 --- a/Scripts/bootargs.sh +++ b/Scripts/bootargs.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/bin/bash +source ./Scripts/lib/parsing.sh set -e #; colorize shell script nc="\033[0m" @@ -6,22 +7,26 @@ red="\033[0;31m" green="\033[0;32m" 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 MYSQL_SERVICE_HOST="127.0.0.1" -#;export MYSQL_SERVICE_HOST="localhost" +export DATABASE_SERVICE_NAME="mysql" +#; Host name (unix) 'localhost' generally replaces '127.0.0.1' (macOS). +#;export MYSQL_SERVICE_HOST="127.0.0.1" +export MYSQL_SERVICE_HOST="localhost" export MYSQL_SERVICE_PORT="3306" +#; To override, use shell parameter -dbase= instead 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 DATABASE_USER="root" +#; To override, shell parameter -p= instead +#;export DATABASE_PASSWORD="" +#. Test configuration ?test=1, ./test_cake.sh +#;export TEST_MYSQL_SERVICE_HOST="127.0.0.1" +export TEST_MYSQL_SERVICE_HOST="localhost" export TEST_MYSQL_SERVICE_PORT="3306" +#; To override, use shell parameter -tbase= instead export TEST_DATABASE_NAME="cakephp_test" -export TEST_DATABASE_USER="root" -export TEST_DATABASE_PASSWORD=${SQL_PASSWORD} +export TEST_DATABASE_USER="test" +#; To override, use shell parameter -t= instead +#;export TEST_DATABASE_PASSWORD="" export FTP_SERVICE_HOST="localhost" export FTP_SERVICE_USER="test" export FTP_SERVICE_PASSWORD="mypassword" @@ -32,3 +37,9 @@ export CAKEPHP_SECURITY_SALT="Word" export CAKEPHP_SECURITY_CIPHER_SEED="01234" #; 0, 1, 2 the higher the more debug data export CAKEPHP_DEBUG_LEVEL=2 +#; Read -p pass -s word <- bootstrap.sh exports +#; export GET_HASH_PASSWORD=wokUd0mccQD2s +if [[ $(parse_arg_exists "-[vV]*|--verbose" $*) ]]; then + echo "DATABASE_PASSWORD=${DATABASE_PASSWORD}" + echo "TEST_DATABASE_PASSWORD=${TEST_DATABASE_PASSWORD}" +fi; diff --git a/Scripts/bootstrap.sh b/Scripts/bootstrap.sh index 19a7e7960..93bda331c 100755 --- a/Scripts/bootstrap.sh +++ b/Scripts/bootstrap.sh @@ -1,6 +1,14 @@ #!/bin/bash set -e -source ./Scripts/bootargs.sh +source ./Scripts/lib/shell_prompt.sh +source ./Scripts/lib/parsing.sh +openshift=$(parse_arg_exists "-[oO]*|--openshift" $*) +if [ $openshift > /dev/null ]; then + echo "Real environment bootargs..." +else + echo "Provided local/test bootargs..." + source ./Scripts/bootargs.sh $* +fi #; #; #; this development phase, don't use the same values for production (no setting means no debugger)! @@ -11,15 +19,17 @@ export CAKEPHP_DEBUG_LEVEL=2 #; check if file etc/constantes_local.properties exist (~ ./configure.sh was run once) #; if [ ! -f ${PHP_CMS_DIR}/e13/etc/constantes.properties ]; then - source ./Scripts/shell_prompt.sh "./configure.sh -c" "configuration" + shell_prompt "./configure.sh -c" "configuration" fi -echo "Configuration begins automatically...${green}" +echo "Configuration begins automatically..." #; hash file that is stored in webroot to allow administrator privileges -hash="${PHP_CMS_DIR}/e13/etc/export_hash_password.sh" -if [ ! -f $hash ]; then - source ./Scripts/shell_prompt.sh "./configure.sh -c -h" "configuration" +if [[ ! $GET_HASH_PASSWORD ]]; then + hash="${PHP_CMS_DIR}/e13/etc/export_hash_password.sh" + if [ ! -f $hash ]; then + shell_prompt "./configure.sh -c -h" "configuration" + fi + source $hash fi -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 diff --git a/Scripts/composer.sh b/Scripts/composer.sh index 8ea1dff9a..4c56ff011 100755 --- a/Scripts/composer.sh +++ b/Scripts/composer.sh @@ -28,4 +28,4 @@ echo -e "\n Please copy and run : ${cyan}rm bin/composer.phar && ./Scripts/composer.sh${nc}\n" #; update plugins and dependencies -php bin/composer.phar update --with-dependencies --apcu-autoloader +php bin/composer.phar update --with-dependencies --apcu-autoloader $* diff --git a/Scripts/config_app_database.sh b/Scripts/config_app_database.sh index a1db43235..106b03be4 100755 --- a/Scripts/config_app_database.sh +++ b/Scripts/config_app_database.sh @@ -1,6 +1,6 @@ #!/bin/bash sqlversion="5.7" -if [ ! $(which mysql) > /dev/null ]; then +if [ ! $(which brew) > /dev/null ]; then echo "Missing homebrew... aborted mysql check."; else if [ ! $(which mysql) > /dev/null ]; then echo -e "Missing MySQL ${sqlversion} database service." brew outdated mysql@${sqlversion} | brew upgrade echo -e "Installing with Homebrew..." @@ -11,7 +11,7 @@ if [ ! $(which mysql) > /dev/null ]; then mysql_upgrade -u root & else mysql --version -fi +fi; fi while [[ "$#" > 0 ]]; do case $1 in *.php) dbfile=$1 @@ -32,4 +32,8 @@ while [[ "$#" > 0 ]]; do case $1 in esac; shift; done if [ ! -h /var/mysql/mysql.sock ]; then echo -e "${orange}Warning:${nc}/var/mysql/mysql.sock symlink not found." +else + echo -e "${green}Notice: mysql.sock symlink was found.${nc}" + #export MYSQL_SERVICE_HOST="127.0.0.1" + #export TEST_MYSQL_SERVICE_HOST="127.0.0.1" fi diff --git a/Scripts/config_etc_pass.sh b/Scripts/config_etc_pass.sh index fd46987f4..7d24c4fa5 100755 --- a/Scripts/config_etc_pass.sh +++ b/Scripts/config_etc_pass.sh @@ -1,5 +1,8 @@ #!/bin/bash pwd=`pwd` +pass="" +salt="" +hash_file="" cd app/webroot/php_cms/e13/etc/ # passed args from shell_prompt while [[ "$#" > 0 ]]; do case $1 in diff --git a/Scripts/cp_bkp_old.sh b/Scripts/cp_bkp_old.sh index da2e58752..4902ddb01 100755 --- a/Scripts/cp_bkp_old.sh +++ b/Scripts/cp_bkp_old.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -if [[ "$#" < 3 ]]; then echo "Usage : ./Scripts/cp_bkp_old.sh "; exit 1; fi +[ $# -lt 3 ] && echo "Usage : $0 " && exit 1 wd=$1 src=$2 dst=$3 diff --git a/Scripts/lib/parsing.sh b/Scripts/lib/parsing.sh new file mode 100755 index 000000000..6cf521da6 --- /dev/null +++ b/Scripts/lib/parsing.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -e +parse_sql_password() { + [ $# -lt 2 ] && echo "Usage: $0 -p|-t|--*sql-password*|*= " && return $FALSE + pass=$(echo $1 | cut -f 2 -d '=') + while true; do case "$pass" in + *sql-password*|-[pPtT]*) + read -sp " +Please, enter the $3 SQL password now: +" pass;; + "") + echo "WARNING: using blank password is unsafe !" + pass="" + break;; + *) + break;; + esac; done + #;echo $pass + export $2=$pass +} +#; export -f parse_sql_password +parse_arg_export() { + [ $# -lt 3 ] && echo "Usage: $0 -= <-pattern*|-PATTERN*> " && return $FALSE + zval=$(echo $1 | cut -f 2 -d '=') + while true; do case "$zval" in + $2|"") + read -sp " +Please, enter the $4 value now: +" zval;; + *) + break;; + esac; done + export $3=$zval +} +#; export -f parse_arg_export +parse_arg_exists() { + [ $# -eq 0 ] && echo "Usage: $0 arguments-list" + arg1=$(echo $1 | cut -f 1 -d '|') + arg2=$(echo $1 | cut -f 2 -d '|') + shift + count=1 + while [[ "$#" > 0 ]]; do case $1 in + $arg1|$arg2 ) echo $count; break;; + *) ;; + esac; ((count++)); shift; done +} +#; export -f parse_arg_exists() diff --git a/Scripts/lib/shell_prompt.sh b/Scripts/lib/shell_prompt.sh new file mode 100755 index 000000000..4328cf401 --- /dev/null +++ b/Scripts/lib/shell_prompt.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -e +shell_prompt() { + [ $# -lt 2 ] && echo "Usage: $0 [-y|n]" && return $FALSE + script=$1 + title=$2 + 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]* ) answer="N";; + + * ) + read -p "Do ${script} now (Y/N) ? " answer;; + esac + # (2) run a script if the user answered Y (yes) or N (no) quit the script + case $answer in + [yY]* ) echo -e "Yes.\n" + source $script + break;; + + [nN]* ) echo -e "No.\n" + break;; + + * ) echo -e "${red}Dude, just enter Y or N, please.\n${nc}";; + esac + done +} +#; export -f shell_prompt diff --git a/Scripts/shell_prompt.sh b/Scripts/shell_prompt.sh deleted file mode 100755 index 14951e5fc..000000000 --- a/Scripts/shell_prompt.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -set -e -script=$1 -title=$2 -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]* ) answer="N";; - - * ) - read -p "Do ${script} now (Y/N) ? " answer;; - esac - # (2) run a script if the user answered Y (yes) or N (no) quit the script - case $answer in - [yY]* ) echo -e "Yes.\n" - source $script - break;; - - [nN]* ) echo -e "No.\n" - break;; - - * ) echo -e "${red}Dude, just enter Y or N, please.\n${nc}";; - esac -done diff --git a/app/Config/Schema/myschema.php b/app/Config/Schema/myschema.php index 6e0815695..91fbe74b3 100644 --- a/app/Config/Schema/myschema.php +++ b/app/Config/Schema/myschema.php @@ -32,7 +32,7 @@ public function after($event = array()) { public $categorie = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'autoIncrement' => true), - 'nom' => array('type' => 'string', 'null' => false, 'length' => 30, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'nom' => array('type' => 'string', 'null' => false, 'length' => 50, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'parent' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 3, 'unsigned' => false, 'key' => 'index'), 'image' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'indexes' => array( diff --git a/app/Config/Schema/schema.php b/app/Config/Schema/schema.php index a0f553c76..2cc9ff849 100644 --- a/app/Config/Schema/schema.php +++ b/app/Config/Schema/schema.php @@ -32,7 +32,7 @@ public function after($event = array()) { public $categorie = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary', 'autoIncrement' => true), - 'nom' => array('type' => 'string', 'null' => false, 'length' => 30, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'nom' => array('type' => 'string', 'null' => false, 'length' => 50, 'key' => 'primary', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'parent' => array('type' => 'integer', 'null' => true, 'default' => null, 'length' => 3, 'unsigned' => false, 'key' => 'index'), 'image' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false), 'indexes' => array( diff --git a/app/Config/boot_profile.cms.php b/app/Config/boot_profile.cms.php index f15320817..a059a8c05 100644 --- a/app/Config/boot_profile.cms.php +++ b/app/Config/boot_profile.cms.php @@ -13,7 +13,9 @@ 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); +App::build(array( + 'Cms' => array(WWW_ROOT . 'php_cms' . DS . 'e13' . DS . 'include' . DS) +), App::REGISTER); /** * Load DebugKit plugin */ diff --git a/app/Config/bootstrap.php b/app/Config/bootstrap.php index 31ce16404..5634e3897 100755 --- a/app/Config/bootstrap.php +++ b/app/Config/bootstrap.php @@ -24,7 +24,21 @@ // Setup a 'default' cache configuration for use in the application. Cache::config('default', array('engine' => 'File')); +// Cache configuration for data that can be cached for a short time only. +Cache::config('short', array( + 'engine' => 'File', + 'duration' => '+1 hours', + 'path' => CACHE, + 'prefix' => 'cake_short_' +)); +// Cache configuration for data that can be cached for a long time. +Cache::config('long', array( + 'engine' => 'File', + 'duration' => '+1 week', + 'probability' => 100, + 'path' => CACHE . 'long' . DS, +)); /** * The settings below can be used to set additional paths to models, views and controllers. * diff --git a/app/Config/database.cms.php b/app/Config/database.cms.php index d6acdf35b..a2a57c598 100644 --- a/app/Config/database.cms.php +++ b/app/Config/database.cms.php @@ -1,5 +1,4 @@ 'Database/Mysql', + # this is an extended Mysql database (providing blob-binary storage) + 'datasource' => 'Database/MysqlCms', 'persistent' => false, //'host' => 'localhost', 'host' => '127.0.0.1', 'port' => '3306', - 'login' => 'test', - 'password' => 'mypassword', + 'login' => 'root', + 'password' => '', 'database' => 'phpcms', 'prefix' => '', 'encoding' => 'utf8', ); public $test = array( - 'datasource' => 'Database/Mysql', + 'datasource' => 'Database/MysqlCms', 'persistent' => false, //'host' => 'localhost', 'host' => '127.0.0.1', 'port' => '3306', 'login' => 'test', - 'password' => 'mypassword', + 'password' => '', 'database' => 'phpcms', 'prefix' => '', 'encoding' => 'utf8', ); public function __construct() { - - $datasource = getenv('DATABASE_ENGINE') ? 'Database/' . ucfirst(getenv('DATABASE_ENGINE')) : FALSE; - - + $datasource = getenv('DATABASE_ENGINE') ? 'Database/' . ucfirst(getenv('DATABASE_ENGINE')) . '_cms' : FALSE; /** a different test/local configuration (shall not be the same as production)*/ $test['host'] = getenv('TEST_' . strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_SERVICE_HOST"); $test['port'] = getenv('TEST_' . strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_SERVICE_PORT"); @@ -104,8 +101,6 @@ public function __construct() { $test['password'] = getenv('TEST_DATABASE_PASSWORD'); $test['database'] = getenv('TEST_DATABASE_NAME'); $test['datasource'] = $datasource; - - $this->redirectIfNull($test, $this->test); $this->test = $test; $default['host'] = getenv(strtoupper(getenv("DATABASE_SERVICE_NAME")) . "_SERVICE_HOST"); @@ -114,17 +109,19 @@ public function __construct() { $default['password'] = getenv("DATABASE_PASSWORD"); $default['database'] = getenv("DATABASE_NAME"); $default['datasource'] = $datasource; + $this->default = $default; + /* copy default to test if necessary */ + $this->redirectIfNull($test, $this->default); + /* copy member variables if null detected */ + $this->redirectIfNull($test, $this->test); $this->redirectIfNull($default, $this->default); - $this->default = $default; } - function redirectIfNull(&$default, $test) { + function redirectIfNull(&$default, $redirect) { foreach ($default as $key => $val) { - if (!$val || $val === "") { - $default[$key] = $test[$key]; + if ((!$val || $val === "") && ($redirect[$key] || $redirect[$key] !== "")) { + $default[$key] = $redirect[$key]; } } } - - } diff --git a/app/Model/Datasource/Database/MysqlCms.php b/app/Model/Datasource/Database/MysqlCms.php new file mode 100644 index 000000000..5933d5c60 --- /dev/null +++ b/app/Model/Datasource/Database/MysqlCms.php @@ -0,0 +1,32 @@ +columns['mediumbinary'] = array('name' => 'mediumblob'); + } + + /** + * Converts database-layer column types to basic types + * + * @param string $real Real database-layer column type (i.e. "varchar(255)") + * @return string Abstract column type (i.e. "string") + */ + public function column($real) { + $s = parent::column($real); + if($s === "text") { + $col = str_replace(')', '', $real); + $limit = $this->length($real); + if (strpos($col, '(') !== false) { + list($col, $vals) = explode('(', $col); + } + if (strpos($col, 'mediumblob') !== false || $col === 'mediumbinary') { + return 'mediumbinary'; + } + } + return $s; + } +} +?> diff --git a/app/Model/Datasource/Database/PostgresCms.php b/app/Model/Datasource/Database/PostgresCms.php new file mode 100644 index 000000000..f81c4ca85 --- /dev/null +++ b/app/Model/Datasource/Database/PostgresCms.php @@ -0,0 +1,11 @@ +columns['mediumbinary'] = array('name' => 'bytea'); + } +} +?> diff --git a/app/Model/Datasource/Database/SqliteCms.php b/app/Model/Datasource/Database/SqliteCms.php new file mode 100644 index 000000000..0e459059f --- /dev/null +++ b/app/Model/Datasource/Database/SqliteCms.php @@ -0,0 +1,32 @@ +columns['mediumbinary'] = array('name' => 'bytea'); + } + + + /** + * Converts database-layer column types to basic types + * + * @param string $real Real database-layer column type (i.e. "varchar(255)") + * @return string Abstract column type (i.e. "string") + */ + public function column($real) { + $s = parent::column($real); + if($s === "text") { + $col = strtolower(str_replace(')', '', $real)); + if (strpos($col, '(') !== false) { + list($col) = explode('(', $col); + } + + if (in_array($col, array('mebiumblob', 'mediumclob'))) { + return 'mediumbinary'; + } + } + return $s; +} +?> diff --git a/app/Vendor/autoload.php b/app/Vendor/autoload.php deleted file mode 100644 index 67053c74b..000000000 --- a/app/Vendor/autoload.php +++ /dev/null @@ -1,7 +0,0 @@ -query("INSERT INTO categorie (nom, parent) VALUES ('" . filter_input(INPUT_POST, 'newcat') . "', '$cp')")) { + $newcat_nom = htmlspecialchars(filter_input(INPUT_POST, 'newcat'), ENCODE_HTML, ENCODE_CS); + if (!$sql->query("INSERT INTO categorie (nom, parent) VALUES ('" . $newcat_nom . "', '$cp')")) { echo $r->lang("cat_sauve_echec", "categories"); $sql->afficheErreurs(); } else { - echo $r->lang("cat_sauve", "categories") . " (" . filter_input(INPUT_POST, 'newcat') . ")."; + echo $r->lang("cat_sauve", "categories") . " (" . $newcat_nom . ")."; } unset($_POST); } @@ -106,7 +107,7 @@ if ($pMethod === 'modifier') { $id = $cat['id']; if ($nom === NULL || !$nom) { echo $r->lang("cat_incomplet", "categories"); - } elseif (!$sql->query("UPDATE categorie SET nom = '" . $nom . "', parent = " . $parent . " WHERE id = " . $id)) { + } elseif (!$sql->query("UPDATE categorie SET nom = '" . htmlspecialchars($nom, ENCODE_HTML, ENCODE_CS) . "', parent = " . $parent . " WHERE id = " . $id)) { echo $r->lang("cat_sauve_echec", "categories"); } else { echo $r->lang("cat_sauve", "categories"); @@ -118,11 +119,11 @@ if ($pMethod === 'modifier') { if (filter_input(INPUT_POST, 'cat_mod')) { $chSelect = new ChampCache("cat_mod", filter_input(INPUT_POST, 'cat_mod')); $cat = CAT_getCat(filter_input(INPUT_POST, 'cat_mod'), $sql); // donnĂˆes de la categorie - $f->nom = $r->lang("modifier", "categories") . CAT_getNom($cat, $sql); + $f->nom = $r->lang("modifier", "categories") . htmlspecialchars_decode(CAT_getNom($cat, $sql), ENCODE_HTML); $chNom = new ChampTexte("new_nom", $r->lang("newcat_lab", "categories"), $r->lang("newcat_dsc", "categories"), 10, NULL, $cat["nom"]); $f->ajouterChamp($chNom); - $chParent = CAT_getSelect($sql, "new_parent", $r->lang("newcat_parent_lab", "categories"), $r->lang("newcat_parent_dsc", "categories") . " (" . $cat["parent"] . ")", $cat['parent'], $cat["nom"]); + $chParent = CAT_getSelect($sql, "new_parent", $r->lang("newcat_parent_lab", "categories"), $r->lang("newcat_parent_dsc", "categories") . " (" . $cat["parent"] . ")", $cat['parent'], htmlspecialchars_decode($cat["nom"], ENCODE_HTML)); $f->ajouterChamp($chParent); } $valid = new ChampValider($r->lang("valider", "form")); diff --git a/app/tmp/cache/long/empty b/app/tmp/cache/long/empty new file mode 100755 index 000000000..e69de29bb diff --git a/composer.json b/composer.json index fe21e65cb..94568eea4 100644 --- a/composer.json +++ b/composer.json @@ -26,10 +26,10 @@ "ext-mcrypt": "You need to install ext-openssl or ext-mcrypt to use AES-256 encryption" }, "require-dev": { - "phpunit/phpunit": "^4", - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpcov": "^2.0", - "cakephp/cakephp-codesniffer": "^3" + "phpunit/phpunit": "^3 || ^4", + "php-coveralls/php-coveralls": "^1 || ^2.1", + "phpunit/phpcov": "^1 || ^2.0", + "cakephp/cakephp-codesniffer": "^1 || ^3" }, "extra": { "installer-paths": { diff --git a/composer.lock b/composer.lock index 4d3dce986..1aab960de 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d8c592cd5beb142f706a5fcc16f0ee0a", + "content-hash": "d4bdf8e6e5f64f050538e34d61eaa577", "packages": [ { "name": "b23prodtm/markdown-plugin", @@ -274,20 +274,20 @@ "packages-dev": [ { "name": "cakephp/cakephp-codesniffer", - "version": "3.0.5", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/cakephp/cakephp-codesniffer.git", - "reference": "7f467fee00fd016b62cf8c85a57750ab2a895e81" + "reference": "682e79fda294c4383e094a2a881e16dcf1130750" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cakephp/cakephp-codesniffer/zipball/7f467fee00fd016b62cf8c85a57750ab2a895e81", - "reference": "7f467fee00fd016b62cf8c85a57750ab2a895e81", + "url": "https://api.github.com/repos/cakephp/cakephp-codesniffer/zipball/682e79fda294c4383e094a2a881e16dcf1130750", + "reference": "682e79fda294c4383e094a2a881e16dcf1130750", "shasum": "" }, "require": { - "php": ">=5.4", + "php": ">=5.6", "squizlabs/php_codesniffer": "^3.0.0" }, "require-dev": { @@ -315,7 +315,7 @@ "codesniffer", "framework" ], - "time": "2018-06-09T16:01:01+00:00" + "time": "2018-11-30T16:04:05+00:00" }, { "name": "doctrine/instantiator", @@ -1833,16 +1833,16 @@ }, { "name": "symfony/config", - "version": "v3.4.18", + "version": "v3.4.19", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "99b2fa8acc244e656cdf324ff419fbe6fd300a4d" + "reference": "8a660daeb65dedbe0b099529f65e61866c055081" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/99b2fa8acc244e656cdf324ff419fbe6fd300a4d", - "reference": "99b2fa8acc244e656cdf324ff419fbe6fd300a4d", + "url": "https://api.github.com/repos/symfony/config/zipball/8a660daeb65dedbe0b099529f65e61866c055081", + "reference": "8a660daeb65dedbe0b099529f65e61866c055081", "shasum": "" }, "require": { @@ -1893,20 +1893,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2018-10-31T09:06:03+00:00" + "time": "2018-11-26T10:17:44+00:00" }, { "name": "symfony/console", - "version": "v2.8.47", + "version": "v2.8.48", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "48ed63767c4add573fb3e9e127d3426db27f78e8" + "reference": "cbcf4b5e233af15cd2bbd50dee1ccc9b7927dc12" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/48ed63767c4add573fb3e9e127d3426db27f78e8", - "reference": "48ed63767c4add573fb3e9e127d3426db27f78e8", + "url": "https://api.github.com/repos/symfony/console/zipball/cbcf4b5e233af15cd2bbd50dee1ccc9b7927dc12", + "reference": "cbcf4b5e233af15cd2bbd50dee1ccc9b7927dc12", "shasum": "" }, "require": { @@ -1954,7 +1954,7 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-10-30T14:26:34+00:00" + "time": "2018-11-20T15:55:20+00:00" }, { "name": "symfony/debug", @@ -2015,16 +2015,16 @@ }, { "name": "symfony/filesystem", - "version": "v3.4.18", + "version": "v3.4.19", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "d69930fc337d767607267d57c20a7403d0a822a4" + "reference": "b49b1ca166bd109900e6a1683d9bb1115727ef2d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/d69930fc337d767607267d57c20a7403d0a822a4", - "reference": "d69930fc337d767607267d57c20a7403d0a822a4", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/b49b1ca166bd109900e6a1683d9bb1115727ef2d", + "reference": "b49b1ca166bd109900e6a1683d9bb1115727ef2d", "shasum": "" }, "require": { @@ -2061,20 +2061,20 @@ ], "description": "Symfony Filesystem Component", "homepage": "https://symfony.com", - "time": "2018-10-02T12:28:39+00:00" + "time": "2018-11-11T19:48:54+00:00" }, { "name": "symfony/finder", - "version": "v3.4.18", + "version": "v3.4.19", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d" + "reference": "6cf2be5cbd0e87aa35c01f80ae0bf40b6798e442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/54ba444dddc5bd5708a34bd095ea67c6eb54644d", - "reference": "54ba444dddc5bd5708a34bd095ea67c6eb54644d", + "url": "https://api.github.com/repos/symfony/finder/zipball/6cf2be5cbd0e87aa35c01f80ae0bf40b6798e442", + "reference": "6cf2be5cbd0e87aa35c01f80ae0bf40b6798e442", "shasum": "" }, "require": { @@ -2110,7 +2110,7 @@ ], "description": "Symfony Finder Component", "homepage": "https://symfony.com", - "time": "2018-10-03T08:46:40+00:00" + "time": "2018-11-11T19:48:54+00:00" }, { "name": "symfony/polyfill-ctype", @@ -2231,16 +2231,16 @@ }, { "name": "symfony/stopwatch", - "version": "v3.4.18", + "version": "v3.4.19", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "05e52a39de52ba690aebaed462b2bc8a9649f0a4" + "reference": "0f43969ab2718de55c1c1158dce046668079788d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/05e52a39de52ba690aebaed462b2bc8a9649f0a4", - "reference": "05e52a39de52ba690aebaed462b2bc8a9649f0a4", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/0f43969ab2718de55c1c1158dce046668079788d", + "reference": "0f43969ab2718de55c1c1158dce046668079788d", "shasum": "" }, "require": { @@ -2276,7 +2276,7 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2018-10-02T12:28:39+00:00" + "time": "2018-11-11T19:48:54+00:00" }, { "name": "symfony/yaml", diff --git a/configure.sh b/configure.sh index aa1f7eb55..b1db45e44 100755 --- a/configure.sh +++ b/configure.sh @@ -1,40 +1,58 @@ #!/bin/bash -source ./Scripts/bootargs.sh - -#; arguments are -args=$* +set -e +source ./Scripts/lib/shell_prompt.sh +source ./Scripts/lib/parsing.sh +openshift=$(parse_arg_exists "-[oO]*|--openshift" $*) +if [ $openshift > /dev/null ]; then + echo "Real environment bootargs..." +else + echo "Provided local/test bootargs..." + source ./Scripts/bootargs.sh $* +fi +saved=("$*") #; if the full set of the arguments exists, there won't be any prompt in the shell while [[ "$#" > 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' + shell_prompt "./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' + shell_prompt "./Scripts/config_etc_pass.sh $*" "${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. + #; 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] [-u]] argument fixes up : Error: Database connection "Mysql" is missing, or could not be created. shift - source ./Scripts/shell_prompt.sh "migrate-database.sh $*" "${cyan}Step 3. Migrate database\n${nc}" '-Y' - ;; + args="" + if [ $openshift > /dev/null ]; then args="--openshift"; fi + shell_prompt "./migrate-database.sh ${args} $*" "${cyan}Step 3. Migrate database\n${nc}" '-Y' + break;; -[sS]*|-[pP]*|-[fF]*) + #; void source script known args shift;; -[mM]*|--submodule) git submodule update --init --recursive --force;; --help ) - echo "./configure.sh [-m] [-c] [-h [-p password -s salt [-f filename]]] [[-d|--mig-database] [-y]] - -c,--const Reset to app/webroot/php_cms/etc/constantes-template.properties - -h,--hash Reset administrator password hash - -p -s [-f ] - -d Migrate Database (see ./migrate-database.sh --help) - -m,--submodule Update sub-modules from Git" + echo "Usage: $0 [-m] [-c] [-h [-p password -s salt [-f filename]]] [[-d|--mig-database] [options]] + -c,--const + Reset to app/webroot/php_cms/etc/constantes-template.properties + -h,--hash + Reset administrator password hash + -p -s [-f ] + Set administrator with md5 . Optional file to save a shell script export. + -m,--submodule + Update sub-modules from Git + -d, --mig-database [options] + Migrate Database (see ./migrate-database.sh --help)" exit 0;; - *) echo "Unknown parameter passed: $1"; exit 1;; + -[oO]*|--openshift );; + -[vV]*|--verbose ) + echo "Passed params : $0 ${saved}";; + *) echo "Unknown parameter passed: $0 $1"; exit 1;; esac; shift; done #; update plugins and dependencies -source ./Scripts/composer.sh +source ./Scripts/composer.sh "-o" echo -e "${green}Fixing some file permissions...${nc}" source ./Scripts/configure_tmp.sh diff --git a/lib/Cake/Model/Datasource/Database/Mysql.php b/lib/Cake/Model/Datasource/Database/Mysql.php index bb07bea7e..7a13c3108 100644 --- a/lib/Cake/Model/Datasource/Database/Mysql.php +++ b/lib/Cake/Model/Datasource/Database/Mysql.php @@ -131,7 +131,6 @@ 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') ); @@ -811,9 +810,6 @@ 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 11497d454..2bf200fee 100644 --- a/lib/Cake/Model/Datasource/Database/Postgres.php +++ b/lib/Cake/Model/Datasource/Database/Postgres.php @@ -69,7 +69,6 @@ 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 50b0afe33..2cf39c356 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -81,7 +81,6 @@ 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') ); @@ -291,9 +290,6 @@ 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 18cc18398..622681cda 100755 --- a/migrate-database.sh +++ b/migrate-database.sh @@ -1,97 +1,141 @@ #!/bin/bash -# HOWTO: connect to the database, a mysql56+ server (must match remote server version) -# must be reachable locally. If it's the 1st time you use this connection, -# Configure it by logging in with shell:$ mysql -u root -# Then execute this SQL statements : create database DATABASE_NAME; # NO QUOTES '' -# use database DATABASE_NAME; -# create user 'DATABASE_USER'@'localhost' -# identified by 'DATABASE_PASSWORD'; -# The values of CakePHP DB VARIABLES available at app/Config/database.php. -# Don't forget to grant all privileges to 'DATABASE_USER'@'localhost' e.g.: -# GRANT ALL ON phpcms.* to 'test'@'localhost' identified by 'mypassword'; -#; -#; Pass as arguments values "[-y|n|u]" to override user prompt, if you're in "nutshell". -#; y fixup socket -#; u fixup socket and update schema (must connect successsfully) -#; set -e -source ./Scripts/bootargs.sh -echo -e " - -${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} : -" -identities=app/Config/identities.sql -if [[ -f $identities ]]; then ./Scripts/cp_bkp_old.sh . $identities ${identities}.old; fi -echo -e " - 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