Fix PHP deprecation: Passing null to parameter #2 ($string) of type string master github/master
authorChristian Weiske <cweiske@cweiske.de>
Fri, 21 Apr 2023 20:26:16 +0000 (22:26 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 21 Apr 2023 20:26:16 +0000 (22:26 +0200)
> PHP Deprecated:  explode(): Passing null to parameter #2 ($string) of type string is deprecated
> in plugins/nextcloud_sql_addressbook/nextcloud_sql_addressbook.php
> on line 128

README.rst
nextcloud_sql_addressbook.php

index 002bfb51dd9b4887f850131575348e29a7480431..6fc9818c2bbd77bae3482a5c24266c0160ec7d1b 100644 (file)
@@ -58,3 +58,10 @@ The address books are only found if the ``principaluri`` in the ``oc_addressbook
 table equals ``principals/users/`` + ``$useremailaddress``.
 
 If you do not see all contacts: Only contacts with an e-mail address are shown.
+
+
+Links
+=====
+- Git repository: https://git.cweiske.de/roundcube-nextcloud_sql_addressbook.git
+- Git mirror: https://github.com/cweiske/roundcube-nextcloud_sql_addressbook
+- Roundcube plugin page: https://plugins.roundcube.net/packages/cweiske/nextcloud_sql_addressbook
index 6b5bb9f11f805c5ed604af15e0e8f9bb117a0491..19cb8f18dc6da4a177916cc7099930164de192d6 100644 (file)
@@ -24,7 +24,12 @@ class nextcloud_sql_addressbook extends rcube_plugin
      * @var string
      */
     protected $prefix = 'oc_';
-    
+
+    /**
+     * Database instance
+     */
+    protected $db;
+
     /**
      * Initialization method, needs to be implemented by the plugin itself
      *
@@ -37,12 +42,12 @@ class nextcloud_sql_addressbook extends rcube_plugin
         $this->add_hook('addressbook_get', [$this, 'addressbook_get']);
 
         $this->rcube = rcube::get_instance();
-        
+
         $this->db = rcube_db::factory(
             $this->rcube->config->get('nextcloud_sql_addressbook_dsn')
         );
         $this->db->set_debug((bool) $this->rcube->config->get('sql_debug'));
-        
+
         $this->prefix = $this->rcube->config->get(
             'nextcloud_sql_addressbook_dbtableprefix', 'oc_'
         );
@@ -88,6 +93,10 @@ class nextcloud_sql_addressbook extends rcube_plugin
      */
     protected function listAddressbooks()
     {
+        if (!isset($this->rcube->user->data)) {
+            return [];
+        }
+
         $principalUri = 'principals/users/'
             . $this->rcube->user->data['username'];
 
@@ -120,6 +129,9 @@ class nextcloud_sql_addressbook extends rcube_plugin
      */
     public function addressbook_get($arguments)
     {
+        if (!isset($arguments['id'])) {
+            return $arguments;
+        }
         $parts = explode('_', $arguments['id'], 2);
         if (count($parts) != 2 || $parts[0] != 'nextcloud') {
             return $arguments;
@@ -131,7 +143,7 @@ class nextcloud_sql_addressbook extends rcube_plugin
         $arguments['instance'] = new nextcloud_sql_addressbook_backend(
             $id, $this->db, $this->prefix
         );
-        
+
         return $arguments;
     }
 }