Carnet: Could not resolve UserManager! Class "UserManager" does not exist

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

Looks like this was fixed upstream: fix IUserManager not defined Ā· CarnetApp/CarnetNextcloud@128ef98 Ā· GitHub

But in anyway, if you fix something like this, a pull request in the corresponding repo is mostlikely very appreciated by the maintainers :slight_smile:

1 Like