From 98f1ae444c427e25e79b1922f4532d5f5ee37576 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 6 Feb 2025 07:21:00 +0000 Subject: [PATCH 1/9] Add composer script for install:prod, remove optimization in dev --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ce332415b6..7b2ba01817 100644 --- a/composer.json +++ b/composer.json @@ -116,7 +116,6 @@ }, "sort-packages": true, "autoloader-suffix": "Friendica", - "optimize-autoloader": true, "preferred-install": "dist", "allow-plugins": { "composer/installers": true, @@ -174,6 +173,7 @@ "@cs:install", "bin/dev/php-cs-fixer/vendor/bin/php-cs-fixer fix" ], - "cs:fix-develop": "TARGET_BRANCH=develop COMMAND=fix bin/dev/fix-codestyle.sh" + "cs:fix-develop": "TARGET_BRANCH=develop COMMAND=fix bin/dev/fix-codestyle.sh", + "install:prod": "@composer install -o --no-dev" } } From d71264993d5f8fe3493f5b87d38050a4222eae3c Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 6 Feb 2025 07:43:52 +0000 Subject: [PATCH 2/9] Update docs and scripts to use the correct composer install script --- .devcontainer/postCreateFriendicaSetup.sh | 4 ++-- doc/Developers-Intro.md | 2 +- doc/Install.md | 4 ++-- doc/Update.md | 6 +++--- doc/de/Install.md | 4 ++-- index.php | 2 +- tests/bootstrap.php | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.devcontainer/postCreateFriendicaSetup.sh b/.devcontainer/postCreateFriendicaSetup.sh index c1c518ca20..1880ac49cc 100755 --- a/.devcontainer/postCreateFriendicaSetup.sh +++ b/.devcontainer/postCreateFriendicaSetup.sh @@ -7,7 +7,7 @@ echo ">>> Friendica Setup" FRIENDICA_PHP_PATH=$(which php) export FRIENDICA_PHP_PATH - + envsubst < $workspaceFolder/.devcontainer/include/autoinstall.config.php > /tmp/autoinstall.config.php cp $workspaceFolder/.devcontainer/include/00apcu.config.php $workspaceFolder/config/00apcu.config.php cp $workspaceFolder/.devcontainer/include/01redis.config.php $workspaceFolder/config/01redis.config.php @@ -19,7 +19,7 @@ cd $DocumentRoot # copy the .htaccess-dist file to .htaccess so that rewrite rules work cp $DocumentRoot/.htaccess-dist $DocumentRoot/.htaccess -bin/composer.phar --no-dev install +bin/composer.phar install # install friendica bin/console autoinstall -f /tmp/autoinstall.config.php diff --git a/doc/Developers-Intro.md b/doc/Developers-Intro.md index 8540109f85..639e1fea74 100644 --- a/doc/Developers-Intro.md +++ b/doc/Developers-Intro.md @@ -62,7 +62,7 @@ If you want to have git automatically update the dependencies with composer, you } # `composer install` if the `composer.lock` file gets changed # to update all the php dependencies - check_run composer.lock "bin/composer.phar install --no-dev" + check_run composer.lock "bin/composer.phar install" just place it into `.git/hooks/post-merge` and make it executable. diff --git a/doc/Install.md b/doc/Install.md index cb4b2de33d..f613b2ffc3 100644 --- a/doc/Install.md +++ b/doc/Install.md @@ -87,7 +87,7 @@ Clone the addon repository (separately): Install the dependencies: - bin/composer.phar install --no-dev + bin/composer.phar run install:prod Make sure the folder *view/smarty3* exists and is writable by the webserver user, in this case *www-data* @@ -98,7 +98,7 @@ Make sure the folder *view/smarty3* exists and is writable by the webserver user If you want to use the development version of Friendica you can switch to the develop branch in the repository by running git checkout develop - bin/composer.phar install + bin/composer.phar run install:prod cd addon git checkout develop diff --git a/doc/Update.md b/doc/Update.md index 40de14082c..b6c5c53e19 100644 --- a/doc/Update.md +++ b/doc/Update.md @@ -14,7 +14,7 @@ If you installed Friendica in the ``path/to/friendica`` folder: * ``.htaccess`` if using Apache web server The following items only need to be copied if they are located inside your friendica path: - * your storage folder as set in **Admin -> Site -> File Upload -> Storage base path** + * your storage folder as set in **Admin -> Site -> File Upload -> Storage base path** * your item cache as set in **Admin -> Site -> Performance -> Path to item cache** * your temp folder as set in **Admin -> Site -> Advanced -> Temp path** 3. Rename the ``path/to/friendica`` folder to ``path/to/friendica_old``. @@ -30,7 +30,7 @@ You can get the latest changes at any time with cd path/to/friendica git pull - bin/composer.phar install --no-dev + bin/composer.phar run install:prod The addon tree has to be updated separately like so: @@ -89,7 +89,7 @@ Some of the updates include the use of foreign keys now that will bump into issu ``` Error 1452 occurred during database update: Cannot add or update a child row: a foreign key constraint fails (`friendica`.`#sql-10ea6_5a6d`, CONSTRAINT `#sql-10ea6_5a6d_ibfk_1` FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`)) -ALTER TABLE `thread` ADD FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE; +ALTER TABLE `thread` ADD FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE; ``` All current known fixes for possible items that can go wrong are as below. diff --git a/doc/de/Install.md b/doc/de/Install.md index ae910e6fab..205127e34e 100644 --- a/doc/de/Install.md +++ b/doc/de/Install.md @@ -59,7 +59,7 @@ Der Linux-Code, mit dem man die Dateien direkt in ein Verzeichnis wie "meinewebs git clone https://github.com/friendica/friendica.git -b stable mywebsite cd mywebsite - bin/composer.phar install + bin/composer.phar run install:prod Stelle sicher, dass der Ordner *view/smarty3* existiert and von dem Webserver-Benutzer beschreibbar ist @@ -85,7 +85,7 @@ Wenn du die Entwickler Version von Friendica verwenden möchtest kannst du auf d Dies tust du mit den folgenden Befehlen git checkout develop - bin/composer.phar install + bin/composer.phar run install:prod cd addon git checkout develop diff --git a/index.php b/index.php index 850d9cd1c0..c1265556f6 100644 --- a/index.php +++ b/index.php @@ -8,7 +8,7 @@ $start_time = microtime(true); if (!file_exists(__DIR__ . '/vendor/autoload.php')) { - die('Vendor path not found. Please execute "bin/composer.phar --no-dev install" on the command line in the web root.'); + die('Vendor path not found. Please execute "bin/composer.phar run install:prod" on the command line in the web root.'); } require __DIR__ . '/vendor/autoload.php'; diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c9fb547ab7..ee628029f4 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; if (!file_exists(__DIR__ . '/../vendor/autoload.php')) { - die('Vendor path not found. Please execute "bin/composer.phar --no-dev install" on the command line in the web root.'); + die('Vendor path not found. Please execute "bin/composer.phar install" on the command line in the web root.'); } require __DIR__ . '/../vendor/autoload.php'; From 2cea3203b56fb4f499699ac69a067dc7f722e363 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 6 Feb 2025 07:47:51 +0000 Subject: [PATCH 3/9] Fix composer path in Vagrant docs --- doc/Vagrant.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Vagrant.md b/doc/Vagrant.md index 16088cd37e..29a2871bd8 100644 --- a/doc/Vagrant.md +++ b/doc/Vagrant.md @@ -18,7 +18,7 @@ What you need to do: Please use an up-to-date vagrant version from https://www.vagrantup.com/downloads.html. 2. Git clone your Friendica repository. Inside, you'll find a `Vagrantfile` and some scripts in the `bin/dev` folder. -Pull the PHP requirements with `bin/composer install`. +Pull the PHP requirements with `bin/composer.phar install`. 3. Run `vagrant up` from inside the friendica clone. This will start the virtual machine. Be patient: When it runs for the first time, it downloads a Debian Server image and installs Friendica. @@ -60,7 +60,7 @@ Trouble Shooting If you see a version mis-match for the _VirtualBox Guest Additions_ between host and guest during the initial setup of the Vagrant VM, you will need to install an addon to Vagrant (ref. [Stack Overflow](https://stackoverflow.com/a/38010683)). Stop the Vagrant VM and run the following command: - $> vagrant plugin install vagrant-vbguest + $> vagrant plugin install vagrant-vbguest On the next Vagrant up, the version problem should be fixed. From c6ee2c461cf7f9a57548fcf9fe6477e213eba414 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 6 Feb 2025 08:29:14 +0000 Subject: [PATCH 4/9] Revert "Refactor Crypto::randomDigits()" This reverts commit 940884e4bd0c1f68757e464f46b4e76c1f4da5b1. --- src/Util/Crypto.php | 9 ++++++++- tests/Unit/Util/CryptoTest.php | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Util/Crypto.php b/src/Util/Crypto.php index 4c0e9b72dc..588be8f932 100644 --- a/src/Util/Crypto.php +++ b/src/Util/Crypto.php @@ -305,6 +305,13 @@ class Crypto */ public static function randomDigits($digits) { - return random_int(0, 10 ** $digits - 1); + $rn = ''; + + // generating cryptographically secure pseudo-random integers + for ($i = 0; $i < $digits; $i++) { + $rn .= random_int(0, 9); + } + + return (int) $rn; } } diff --git a/tests/Unit/Util/CryptoTest.php b/tests/Unit/Util/CryptoTest.php index 41fb1e2826..55d24562a9 100644 --- a/tests/Unit/Util/CryptoTest.php +++ b/tests/Unit/Util/CryptoTest.php @@ -21,10 +21,11 @@ class CryptoTest extends TestCase { $random_int = $this->getFunctionMock('Friendica\Util', 'random_int'); $random_int->expects($this->any())->willReturnCallback(function ($min, $max) { - return 12345678; + return 1; }); - self::assertSame(12345678, Crypto::randomDigits(8)); + self::assertSame(1, Crypto::randomDigits(1)); + self::assertSame(11111111, Crypto::randomDigits(8)); } public function testDiasporaPubRsaToMe() From c7b1961d02deb873439c694ea1cba8f7406c666c Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 6 Feb 2025 08:30:05 +0000 Subject: [PATCH 5/9] Fix return type of randomDigits --- src/Util/Crypto.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Util/Crypto.php b/src/Util/Crypto.php index 588be8f932..084ae567ea 100644 --- a/src/Util/Crypto.php +++ b/src/Util/Crypto.php @@ -299,11 +299,11 @@ class Crypto * Creates cryptographic secure random digits * * @param string $digits The count of digits - * @return int The random Digits + * @return string The random Digits * * @throws \Exception In case 'random_int' isn't usable */ - public static function randomDigits($digits) + public static function randomDigits($digits): string { $rn = ''; @@ -312,6 +312,6 @@ class Crypto $rn .= random_int(0, 9); } - return (int) $rn; + return $rn; } } From 006ff7be8f13e0ee2893de854e4b3965d108e090 Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 6 Feb 2025 08:33:18 +0000 Subject: [PATCH 6/9] Fix tests --- tests/Unit/Util/CryptoTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/Util/CryptoTest.php b/tests/Unit/Util/CryptoTest.php index 55d24562a9..d04e0323c3 100644 --- a/tests/Unit/Util/CryptoTest.php +++ b/tests/Unit/Util/CryptoTest.php @@ -24,8 +24,8 @@ class CryptoTest extends TestCase return 1; }); - self::assertSame(1, Crypto::randomDigits(1)); - self::assertSame(11111111, Crypto::randomDigits(8)); + self::assertSame('1', Crypto::randomDigits(1)); + self::assertSame('11111111', Crypto::randomDigits(8)); } public function testDiasporaPubRsaToMe() From 7812a6d8feeb235f689692ee0b3907cb6549517d Mon Sep 17 00:00:00 2001 From: ne20002 Date: Thu, 6 Feb 2025 09:21:33 +0000 Subject: [PATCH 7/9] Downgrade shebang from bin/bash to bin/sh --- bin/console | 8 ++++---- bin/run_xgettext.sh | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/bin/console b/bin/console index 6d0d088732..82a0510c66 100755 --- a/bin/console +++ b/bin/console @@ -1,14 +1,14 @@ -#!/bin/bash +#!/bin/sh # SPDX-FileCopyrightText: 2010 - 2024 the Friendica project # # SPDX-License-Identifier: CC0-1.0 -dir=$(cd "${0%[/\\]*}" > /dev/null; pwd) +dir=$(cd "$(dirname "$0")" > /dev/null 2>&1; pwd) -if [[ -d /proc/cygdrive && $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then +if [ -d /proc/cygdrive ] && [ "$(which php)" = "$(readlink -n /proc/cygdrive)/*" ]; then # We are in Cygwin using Windows php, so the path must be translated - dir=$(cygpath -m "$dir"); + dir=$(cygpath -m "$dir") fi php "${dir}/console.php" "$@" diff --git a/bin/run_xgettext.sh b/bin/run_xgettext.sh index 1375f2b276..b947b43a35 100755 --- a/bin/run_xgettext.sh +++ b/bin/run_xgettext.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # SPDX-FileCopyrightText: 2010 - 2024 the Friendica project # @@ -6,8 +6,8 @@ set -eo pipefail -function resolve { - if [ "$(uname)" == "Darwin" ] +resolve() { + if [ "$(uname)" = "Darwin" ] then realpath "$1" else @@ -17,26 +17,26 @@ function resolve { FULLPATH=$(dirname "$(resolve "$0")") -if [ "$1" == "--help" ] || [ "$1" == "-h" ] +if [ "$1" = "--help" ] || [ "$1" = "-h" ] then echo "$(basename "$(resolve "$0")") [options]" echo echo "-a | --addon extract strings from addon 'name'" - echo "-s | --single single addon mode: extract string from current folder" + echo "-s | --single single addon mode: extract string from current folder" exit fi MODE='default' ADDONNAME= -if [ "$1" == "--addon" ] || [ "$1" == "-a" ] +if [ "$1" = "--addon" ] || [ "$1" = "-a" ] then MODE='addon' - if [ -z "$2" ]; then echo -e "ERROR: missing addon name\n\nrun_xgettext.sh -a "; exit 1; fi + if [ -z "$2" ]; then echo "ERROR: missing addon name\n\nrun_xgettext.sh -a "; exit 1; fi ADDONNAME=$2 if [ ! -d "$FULLPATH/../addon/$ADDONNAME" ]; then echo "ERROR: addon '$ADDONNAME' not found"; exit 2; fi fi -if [ "$1" == "--single" ] || [ "$1" == "-s" ] +if [ "$1" = "--single" ] || [ "$1" = "-s" ] then MODE='single' fi @@ -70,7 +70,6 @@ case "$MODE" in ;; esac - KEYWORDS="-k -kt -ktt:1,2" echo "Extract strings to $OUTFILE.." @@ -119,7 +118,7 @@ case "$MODE" in ;; esac -if [ "" != "$1" ] && [ "$MODE" == "default" ] +if [ -n "$1" ] && [ "$MODE" = "default" ] then UPDATEFILE="$(resolve "${FULLPATH}/$1")" echo "Merging new strings to $UPDATEFILE.." From 2ceded19c4852a64a704d87460ac1a2f5c77c1a8 Mon Sep 17 00:00:00 2001 From: ne20002 Date: Thu, 6 Feb 2025 17:53:09 +0000 Subject: [PATCH 8/9] Followup to #14790 - revert to /bin/bash for run_xgettext.sh --- bin/run_xgettext.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/run_xgettext.sh b/bin/run_xgettext.sh index b947b43a35..85f5004235 100755 --- a/bin/run_xgettext.sh +++ b/bin/run_xgettext.sh @@ -1,10 +1,10 @@ -#!/bin/sh +#!/bin/bash # SPDX-FileCopyrightText: 2010 - 2024 the Friendica project # # SPDX-License-Identifier: CC0-1.0 -set -eo pipefail +set -e -o pipefail resolve() { if [ "$(uname)" = "Darwin" ] From 6cd92da46c8b7eaa3a9c724fe3cda2e22fd227ca Mon Sep 17 00:00:00 2001 From: ne20002 Date: Thu, 6 Feb 2025 18:18:11 +0000 Subject: [PATCH 9/9] Fix for PR #14790 --- bin/run_xgettext.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/run_xgettext.sh b/bin/run_xgettext.sh index 85f5004235..ec5cb955d0 100755 --- a/bin/run_xgettext.sh +++ b/bin/run_xgettext.sh @@ -1,10 +1,17 @@ -#!/bin/bash +#!/bin/sh # SPDX-FileCopyrightText: 2010 - 2024 the Friendica project # # SPDX-License-Identifier: CC0-1.0 -set -e -o pipefail +set -e + +# Custom function to handle pipefail behavior +pipefail() { + local cmd="$1" + shift + { eval "$cmd"; } || exit 1 +} resolve() { if [ "$(uname)" = "Darwin" ] @@ -78,13 +85,13 @@ echo "Extract strings to $OUTFILE.." # shellcheck disable=SC2086 # $FINDOPTS is meant to be split find_result=$(find "$FINDSTARTDIR" $FINDOPTS -name "*.php" -type f | LC_ALL=C sort -s) -total_files=$(wc -l <<< "${find_result}") +total_files=$(echo "${find_result}" | wc -l) count=1 for file in $find_result do - echo -ne " \r" - echo -ne "Reading file $count/$total_files..." + printf " \r" + printf "Reading file %d/%d..." "$count" "$total_files" # On Windows, find still outputs the name of pruned folders if [ ! -d "$file" ] @@ -93,9 +100,8 @@ do xgettext $KEYWORDS --no-wrap -j -o "$OUTFILE" --from-code=UTF-8 "$file" || exit 1 sed -i.bkp "s/CHARSET/UTF-8/g" "$OUTFILE" fi - (( count++ )) + count=$((count + 1)) done -echo -ne "\n" echo "Interpolate metadata.."