I have this error on the console, when using
docker exec -u www-data -it $CONTAINIER_NAME php occ notify_push:self-test
Failed to construct console command āOCA\\Carnet\\Command\\Cacheā: Could not resolve UserManager! Class āUserManagerā does not exist
this is my fix:
#!/bin/bash
# Fix for Carnet App: "Failed to construct console command 'OCA\Carnet\Command\Cache': Could not resolve UserManager!"
#
# Root Cause:
# In custom_apps/carnet/lib/Command/Cache.php the constructor parameter
# $UserManager has no type-hint. Nextcloud's Dependency Injection cannot resolve it
# without the interface OCP\IUserManager.
#
# This fix:
# 1. Adds "use OCP\IUserManager;" import
# 2. Adds the IUserManager type-hint to the $UserManager parameter
#
# When to run:
# After every Nextcloud or Carnet app update, since the fix will be overwritten.
#
# Usage:
# bash fix-carnet-generic.sh
CONTAINER="nextcloud-app-1"
FILE="/var/www/html/custom_apps/carnet/lib/Command/Cache.php"
echo "--- Fixing Carnet in $CONTAINER ---"
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
echo " ā Container $CONTAINER is not running"
exit 1
fi
if ! docker exec "$CONTAINER" test -f "$FILE"; then
echo " ā Carnet not installed ($FILE not found)"
exit 1
fi
if docker exec "$CONTAINER" grep -q "use OCP\\\\IUserManager;" "$FILE"; then
echo " ā Already fixed"
exit 0
fi
docker exec "$CONTAINER" sed -i 's/use OCP\\IConfig;/use OCP\\IConfig;\nuse OCP\\IUserManager;/' "$FILE"
docker exec "$CONTAINER" sed -i 's/\$UserManager)/IUserManager \$UserManager)/' "$FILE"
if docker exec "$CONTAINER" grep -q "use OCP\\\\IUserManager;" "$FILE"; then
echo " ā Fixed"
else
echo " ā Fix failed!"
exit 1
fi
echo ""
echo "Verifying (no 'Carnet' error should appear):"
RESULT=$(docker exec -u www-data "$CONTAINER" php occ status 2>&1 | grep -i carnet)
if [ -z "$RESULT" ]; then
echo " ā OK"
else
echo " ā $RESULT"
fi