Skip to content

Commit

Permalink
Upgrade development Dockerfile to PHP 8 + setup fixes (#1142)
Browse files Browse the repository at this point in the history
* Upgrade development Dockerfile to PHP 8

* Fixes to get the setup process to work OOTB

* Upgrade to PHP 8.2 and xdebug 3.3.1

* Remove redundant patch (see 2.sql)

* Update schema version
  • Loading branch information
markspolakovs authored Feb 21, 2024
1 parent a50fd2f commit b759efc
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.4-apache
FROM php:8.2-apache

RUN apt-get update && apt-get install -y libpq-dev libpng-dev libjpeg-dev libldap-dev unzip \
libcurl4-openssl-dev libxslt-dev git libz-dev libzip-dev libmemcached-dev \
Expand All @@ -9,8 +9,8 @@ RUN docker-php-ext-install pgsql pdo_pgsql gd ldap curl xsl zip
RUN pecl install memcached && \
echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini

RUN pecl install xdebug-3.1.1 && docker-php-ext-enable xdebug \
&& echo 'zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so"' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
RUN pecl install xdebug-3.3.1 && docker-php-ext-enable xdebug \
&& echo 'zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so"' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.client_port=9003' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.mode=develop,debug' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo 'xdebug.start_with_request=yes' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
Expand Down
22 changes: 1 addition & 21 deletions build.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyRadio" default="build">
<property name="vendordir" value="${basedir}/src/vendor/bin" />
<target name="build" depends="prepare,composer,lint,phploc,pdepend,phpmd-ci,phpcs-ci,eslint-ci,phpcpd,phpdox"/>
<target name="build" depends="prepare,composer,lint,pdepend,phpmd-ci,phpcs-ci,eslint-ci,phpdox"/>

<target name="clean" description="Cleanup build artifacts">
<delete dir="${basedir}/build/api"/>
Expand Down Expand Up @@ -45,18 +45,6 @@
</apply>
</target>

<target name="phploc" description="Measure project size using PHPLOC">
<exec executable="${vendordir}/phploc">
<arg value="--count-tests" />
<arg value="--log-csv" />
<arg value="${basedir}/build/logs/phploc.csv" />
<arg value="--log-xml" />
<arg value="${basedir}/build/logs/phploc.xml" />
<arg value="--exclude=vendor" />
<arg path="${basedir}/src" />
</exec>
</target>

<target name="pdepend" description="Calculate software metrics using PHP_Depend">
<exec executable="${vendordir}/pdepend">
<arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" />
Expand Down Expand Up @@ -102,14 +90,6 @@
</exec>
</target>

<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="${vendordir}/phpcpd">
<arg value="--log-pmd=${basedir}/build/logs/pmd-cpd.xml" />
<arg value="--exclude=vendor" />
<arg path="${basedir}/src" />
</exec>
</target>

<target name="phpdox" description="Generate API documentation using phpDox">
<exec executable="${vendordir}/phpdox" />
</target>
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"php": ">=7.4 <8.0",
"php": ">=7.4",
"james-heinrich/getid3": "~1.9",
"ezyang/htmlpurifier": "~4.10",
"google/recaptcha": "~1.1",
Expand All @@ -10,16 +10,15 @@
"webonyx/graphql-php": "^0.13.8",
"ext-json": "*",
"geoip2/geoip2": "^2.10.0",
"spatie/icalendar-generator": "^2.1"
"spatie/icalendar-generator": "^2.1",
"ext-pgsql": "*"
},
"require-dev": {
"squizlabs/php_codesniffer": "~3.5",
"pdepend/pdepend": "~2.5",
"phpmd/phpmd": "~2.6",
"sebastian/phpcpd": "~3.0",
"phploc/phploc": "~4.0",
"theseer/phpdox": "~0.11",
"codeception/codeception": "~2.4",
"codeception/codeception": "~4.2",
"flow/jsonpath": "~0.4"
},
"config": {
Expand Down
3 changes: 3 additions & 0 deletions schema/patches/18.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CREATE TYPE deletion AS ENUM ('default', 'informed', 'optout', 'deleted');

ALTER TABLE public.member
ADD gdpr_accepted boolean default(false);

ALTER TABLE Public.member
ADD data_removal deletion DEFAULT('default');

Expand Down
6 changes: 5 additions & 1 deletion src/Classes/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ public function query($sql, $params = [], $rollback = false)
pg_send_query_params($this->db, $sql, $params);
}
$result = pg_get_result($this->db);
$errmsg = pg_result_error($result);
if ($result === FALSE) {
$errmsg = pg_last_error($this->db);
} else {
$errmsg = pg_result_error($result);
}
if ($errmsg != "") {
if ($this->in_transaction) {
pg_query($this->db, 'ROLLBACK');
Expand Down
7 changes: 5 additions & 2 deletions src/Classes/MyRadio/AuthUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ public static function diffPermissions($perms, $diffPerms)
public static function addPermission($descr, $constant)
{
$value = (int) Database::getInstance()->fetchColumn(
// This is for all intents and purposes an ON CONFLICT DO NOTHING, but if we did use that
// then the RETURNING wouldn't return the ID which we need, hence the no-op UPDATE.
'INSERT INTO public.l_action (descr, phpconstant)
VALUES ($1, $2) RETURNING typeid',
VALUES ($1, $2) ON CONFLICT (phpconstant) DO UPDATE SET descr = $1 RETURNING typeid',
[$descr, $constant]
)[0];
define($constant, $value);
Expand All @@ -428,7 +430,8 @@ public static function addActionPermission($module, $action, $permission)
$db = Database::getInstance();
$db->query(
'INSERT INTO myury.act_permission (serviceid, moduleid, actionid, typeid)
VALUES ($1, $2, $3, $4)',
VALUES ($1, $2, $3, $4)
ON CONFLICT (serviceid, moduleid, actionid, typeid) DO NOTHING',
[Config::$service_id, $module, $action, $permission]
);
}
Expand Down
14 changes: 6 additions & 8 deletions src/Controllers/Setup/dbdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

$db = Database::getInstance();
$db->query(
'INSERT INTO myradio.schema (attr, value) VALUES (\'datamode\', $1)',
'INSERT INTO myradio.schema (attr, value) VALUES (\'datamode\', $1) ON CONFLICT (attr) DO UPDATE SET value = $1 WHERE schema.attr = \'datamode\'',
[$mode]
);

Expand All @@ -45,11 +45,7 @@ function setUpFullActionsAuth()
CoreUtils::getActionId($module, $action[1]);
}
foreach (json_decode(file_get_contents(SCHEMA_DIR.'data-auth.json')) as $auth) {
try {
AuthUtils::addPermission($auth[0], $auth[1]);
} catch (MyRadioException $e) {
$warnings[] = 'Failed to create Permission "'.$auth[0].'". It may already exist.';
}
AuthUtils::addPermission($auth[0], $auth[1]);
}
foreach (json_decode(file_get_contents(SCHEMA_DIR.'data-actionsauth.json')) as $actionauth) {
$module = CoreUtils::getModuleId($actionauth[0]);
Expand All @@ -59,8 +55,10 @@ function setUpFullActionsAuth()
}
foreach (json_decode(file_get_contents(SCHEMA_DIR.'data-apiauth.json')) as $apiauth) {
$db->query(
'INSERT INTO myury.api_method_auth (class_name, method_name, typeid) VALUES ($1, $2, $3)',
[$apiauth[0], $apiauth[1], constant($apiauth[2])]
'INSERT INTO myury.api_method_auth (class_name, method_name, typeid)
VALUES ($1, $2, $3)
ON CONFLICT (class_name, method_name, typeid) DO NOTHING',
[$apiauth[0], $apiauth[1], $apiauth[2] === null ? null : constant($apiauth[2])]
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Controllers/root.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* This number is incremented every time a database patch is released.
* Patches are scripts in schema/patches.
*/
define('MYRADIO_CURRENT_SCHEMA_VERSION', 15);
define('MYRADIO_CURRENT_SCHEMA_VERSION', 18);

/*
* Turn on Error Reporting for the start. Once the Config object is loaded
Expand Down Expand Up @@ -56,7 +56,7 @@
* Load configuration specific to this system.
* Or, if it doesn't exist, kick into setup.
*/
if (stream_resolve_include_path('MyRadio_Config.local.php')) {
if (stream_resolve_include_path('MyRadio_Config.local.php') && file_exists(stream_resolve_include_path('MyRadio_Config.local.php'))) {
require_once 'MyRadio_Config.local.php';
if (Config::$setup === true) {
require 'Controllers/Setup/root.php';
Expand Down Expand Up @@ -96,7 +96,7 @@ function ($e) {
* Turn off visible error reporting, if needed
* must come after AuthUtils::setUpAuth()
*/
if (!Config::$display_errors && !AuthUtils::hasPermission(AUTH_SHOWERRORS)) {
if (!Config::$display_errors && defined('AUTH_SHOWERRORS') && !AuthUtils::hasPermission(AUTH_SHOWERRORS)) {
ini_set('display_errors', 'Off');
}

Expand Down

0 comments on commit b759efc

Please sign in to comment.