mstilkerich / rcmcarddav

CardDAV plugin for RoundCube Webmailer
GNU General Public License v2.0
258 stars 81 forks source link

addressbook name substitution %N #436

Closed quenenni closed 1 year ago

quenenni commented 1 year ago

If I use in config.inc.php the option

    // Auto-discovered addressbook attributes, and for extra addressbooks if not overridden there
    //// optional attributes
    'name'         => '%N',

I have this error:

==> errors.log <==
[19-Apr-2023 21:18:05 Europe/Berlin] PHP Fatal error:  Uncaught Error: Call to undefined method MStilkerich\CardDavClient\AddressbookCollection::getDisplayName() in /var/www/roundcube-test/plugins/carddav/src/Frontend/AddressbookManager.p
hp:697
Stack trace:
#0 /var/www/roundcube-test/plugins/carddav/src/Frontend/AddressbookManager.php(655): MStilkerich\RCMCardDAV\Frontend\AddressbookManager->replacePlaceholdersAbookName()
#1 /var/www/roundcube-test/plugins/carddav/carddav.php(359): MStilkerich\RCMCardDAV\Frontend\AddressbookManager->discoverAddressbooks()
#2 /var/www/roundcube-test/program/lib/Roundcube/rcube_plugin_api.php(518): carddav->afterLogin()
#3 /var/www/roundcube-test/program/actions/login/oauth.php(62): rcube_plugin_api->exec_hook()
#4 /var/www/roundcube-test/index.php(198): rcmail_action_login_oauth->run()
#5 {main}
  thrown in /var/www/roundcube-test/plugins/carddav/src/Frontend/AddressbookManager.php on line 697

I can see this function in vendor/mstilkerich/carddavclient/src/AddressbookCollection.php. But I don't know why it doens't have this public method getDisplayName() available.

If I use '%c' (all except %N and %D) as substitute for the addressbook name, everything is working nicely.

mstilkerich commented 1 year ago

The getDisplayName() function is available since carddavclient library version 1.3.0, which is required for rcmcarddav v5.

Since it is not available, but composer would take care of it being installed when you install rcmcarddav v5, my guess is that you might have two versions of carddavclient installed, one inside the plugin directory (roundcube_install_path/plugins/carddav/vendor) and one inside the roundcube main vendor directory (roundcube_install_path/vendor). This can either happen if you ran composer inside the plugin directory anytime before or you used a tarball installation method and later on upgraded using composer without cleaning up the tarball version.

Anyway, to check:

  1. If there is a roundcube_install_path/plugins/carddav/vendor directory, delete it.
  2. In the roundcube main directory, run composer show. It should show mstilkerich/carddavclient with version v1.3.0.
  3. If it shows an older version, run composer update --no-dev
quenenni commented 1 year ago

Thanks for the help.

Since it is not available, but composer would take care of it being installed when you install rcmcarddav v5, I didn't use composer when I upgraded my plugin.

As the install doc mentions, "Note: Release tarballs prior to v4.1.0 lack the dependencies and require to run composer. See the INSTALL.md file inside that tarball for the appropriate instructions.". As I donwloaded v5, I thought I didn't need to use composer.

my guess is that you might have two versions of carddavclient installed, one inside the plugin directory (roundcube_install_path/plugins/carddav/vendor) and one inside the roundcube main vendor directory (roundcube_install_path/vendor)

You're right:

roundcube/plugins/carddav/vendor/mstilkerich/carddavclient/  (## Version 1.3 : function getDisplayName exists)
roundcube/vendor/mstilkerich/carddavclient/   (## Version 1.2.1 : function getDisplayName doens't exists)

This can either happen if you ran composer inside the plugin directory anytime before or you used a tarball installation method and later on upgraded using composer without cleaning up the tarball version

What happened since the first attempt to upgrade to v5.

The only time we used composer in carddav folder was to install the v4.3 version.

Is there a way to adapt this or is the only way to fix this is to uninstall completely the plugin and re-install it?

Thanks.

[EDIT] To upgrade my RC, I used the script ./bin/installto.sh <TARGET-FOLDER> as mentioned in their documentation.

mstilkerich commented 1 year ago

First you have to decide whether you want to install the plugin using composer or tarball. I suspect you did at least once install using composer, because otherwise there should not be a carddavclient library in the roundcube vendor directory. I recommend installation using composer, since you can avoid the mess of having two different versions of the same library installed (there are libraries which both roundcube and rcmcarddav use, e.g. guzzle).

If you want to install using composer

If you want to install using tarball

mstilkerich commented 1 year ago

Could you fix the issue?

quenenni commented 1 year ago

I'm planning to try to fix it this week. I was under heavy load last week (and had 2 days without internet in the middle of this, so much fun).

Sorry for the delay.

mstilkerich commented 1 year ago

Closing this for lack of feedback and since I believe there is no issue with rcmcarddav here.

quenenni commented 1 year ago

Sorry for the delay. I was able to do another try to update my rouncube + plugin, and the plugin update failed.

I started from a new copy of our prod setup, meaning, with carddav plugin to v4.7 and without any attempts to update it.

Here are the exact steps I did:

update [--with WITH] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--dev] [--no-dev] [--lock] [--no-install] [--no-autoloader] [--no-scripts] [--no-suggest] [--no-progress] [-w|--with-dependencies] [-W|--with-all-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] []...


ATTENTION: Update dependencies by running php composer.phar update --no-dev

This instance of Roundcube is up-to-date.

My Roundcube was updated but an error when trying to update the carddav plugin.
- I went into my RC folder to execete again the composer command:

sudo -u www-data php composer.phar update --no-dev Loading composer repositories with package information Info from https://repo.packagist.org: #StandWithUkraine Updating dependencies Nothing to modify in lock file Installing dependencies from lock file Package operations: 0 installs, 1 update, 0 removals

update [--with WITH] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--dev] [--no-dev] [--lock] [--no-install] [--no-autoloader] [--no-scripts] [--no-suggest] [--no-progress] [-w|--with-dependencies] [-W|--with-all-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] []...


I then decided to try the upgrade process as explained in carddav plugin doc:
- I removed the carddav plugin folder (rm -R plugins/carddav)
- I edited the composer.json from RC and modified:

I switched this line: "roundcube/carddav": "dev-master",

by this line: "roundcube/carddav": "^5.0.0",

- I executed the command `sudo -u www-data composer update --no-dev -o`

PHP Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Symfony/Component/Console/Helper/HelperSet.php on line 103

Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Symfony/Component/Console/Helper/HelperSet.php on line 103 Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /usr/share/php/JsonSchema/Constraints/Constraint.php:48 Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Symfony\Component\Process\Process::getIterator($flags = 0) should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Symfony/Component/Process/Process.php:622
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Composer\Repository\CompositeRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/Repository/CompositeRepository.php:180
Loading composer repositories with package information Deprecation Notice: Implicit conversion from float 204.57 to int loses precision in /usr/share/php/Composer/Platform/Version.php:100 Info from https://repo.packagist.org: #StandWithUkraine Deprecation Notice: Return type of Composer\DependencyResolver\Pool::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/Pool.php:76
Updating dependencies Deprecation Notice: Return type of Composer\DependencyResolver\RuleSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/RuleSet.php:116
Deprecation Notice: Return type of Composer\DependencyResolver\RuleSet::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/RuleSet.php:101
Deprecation Notice: Return type of Composer\DependencyResolver\Decisions::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/Decisions.php:155
Deprecation Notice: Return type of Composer\DependencyResolver\Decisions::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/Decisions.php:165
Deprecation Notice: Return type of Composer\DependencyResolver\Decisions::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/Decisions.php:160
Deprecation Notice: Return type of Composer\DependencyResolver\Decisions::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/Decisions.php:170
Deprecation Notice: Return type of Composer\DependencyResolver\Decisions::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/Decisions.php:150
Deprecation Notice: Return type of Composer\DependencyResolver\Decisions::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/Decisions.php:145
Deprecation Notice: Return type of Composer\DependencyResolver\RuleSetIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/RuleSetIterator.php:36
Deprecation Notice: Return type of Composer\DependencyResolver\RuleSetIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/RuleSetIterator.php:46
Deprecation Notice: Return type of Composer\DependencyResolver\RuleSetIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/RuleSetIterator.php:41 Deprecation Notice: Return type of Composer\DependencyResolver\RuleSetIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/RuleSetIterator.php:89
Deprecation Notice: Return type of Composer\DependencyResolver\RuleSetIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /usr/share/php/Composer/DependencyResolver/RuleSetIterator.php:70
Lock file operations: 0 installs, 1 update, 0 removals

In autoload_real.php line 75:

require(/var/www/roundcube-test/vendor/composer/../symfony/polyfill-intl-normalizer/bootstrap.php): Failed to open stream: No such file or directory


At this point, I have my Rc updated but no more carddav plugin at all. 
The Db tables for carddav didn't change at all.

Php version used is v8.1.18
mstilkerich commented 1 year ago

Have you tried

If you get errors in the process (uninstalling roundcube plugins with composer can raise errors), run composer dump-autoload -o, and then composer update --no-dev -o

If this doesn’t help I have no further ideas and would suggest to first remove the plugin (keep the DB) and reinstall it. That is, remove it from composer json, delete the carddav directory (backup your config), run composer update and dump autoload commands to remove it from the composer database, and then install again with composer require command.

quenenni commented 1 year ago

Big big thanks. The command composer dump-autoload -o, indeed fixed the problem.

After it, the command composer update --no-dev -o installed the right version of the carddav plugin.

On first connexion to Roundcube, the carddav plugin updated without problem the DB and the addressbooks from our cloud were synchronised into Roundcube.. and that's amazing.

Thank you very much for all the help you gave me. It wouldn't have been possible to make it work without your help.