Skip to content

Commit

Permalink
Adjust interfaces to upcoming roundcube 1.7 changes (Fixes: #467)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstilkerich committed Apr 3, 2024
1 parent 3cfb732 commit a140f57
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
6 changes: 5 additions & 1 deletion carddav.php
Expand Up @@ -206,7 +206,11 @@ public function inputValue(string $id, bool $allowHtml, int $source = rcube_util
public function showMessage(string $msg, string $msgType = 'notice', bool $override = false, int $timeout = 0): void
{
$rcube = rcube::get_instance();
$rcube->output->show_message($msg, $msgType, null, $override, $timeout);
$output = $rcube->output;

if ($output instanceof rcmail_output) {
$output->show_message($msg, $msgType, null, $override, $timeout);
}
}

public function clientCommand(string $method, ...$arguments): void
Expand Down
17 changes: 10 additions & 7 deletions src/Addressbook.php
Expand Up @@ -448,7 +448,7 @@ public function get_record($id, $assoc = false)
* @param ?string $sort_order Sort order
*/
// phpcs:ignore PSR1.Methods.CamelCapsMethodName -- method name defined by rcube_addressbook class
public function set_sort_order($sort_col, $sort_order = null): void
public function set_sort_order($sort_col = null, $sort_order = null): void
{
if (isset($sort_col) && key_exists($sort_col, $this->coltypes)) {
$this->sort_col = $sort_col;
Expand Down Expand Up @@ -564,8 +564,8 @@ public function update($id, $save_cols)
/**
* Mark one or more contact records as deleted
*
* @param array $ids Record identifiers
* @param bool $force Remove records irreversible (see self::undelete)
* @param array|string $ids Record identifiers
* @param bool $force Remove records irreversible (see self::undelete)
*
* @return int|false Number of removed records, False on failure
*/
Expand All @@ -575,6 +575,10 @@ public function delete($ids, $force = true)
$logger = $infra->logger();
$db = $infra->db();

if (is_string($ids)) {
$ids = explode(self::SEPARATOR, $ids);
}

/** @var list<string> $ids */
$deleted = 0;
$logger->info("delete([" . implode(",", $ids) . "])");
Expand Down Expand Up @@ -691,7 +695,7 @@ public function delete_all($with_groups = false): void
* This filter mechanism is applied in addition to other filter mechanisms, see the description of the count()
* operation.
*
* @param null|0|string $group_id Database identifier of the group. 0/"0"/null to reset the group filter.
* @param null|int|string $group_id Database identifier of the group. 0/"0"/null to reset the group filter.
*/
// phpcs:ignore PSR1.Methods.CamelCapsMethodName -- method name defined by rcube_addressbook class
public function set_group($group_id): void
Expand All @@ -703,6 +707,7 @@ public function set_group($group_id): void
$logger->debug("set_group($group_id)");

if ($group_id) {
$group_id = (string) $group_id;
$db = $infra->db();
// check for valid ID with the database - this throws an exception if the group cannot be found
$db->lookup(["id" => $group_id, "abook_id" => $this->id], ["id"], "groups");
Expand Down Expand Up @@ -994,9 +999,7 @@ public function add_to_group($group_id, $ids): int
$davAbook = $this->getCardDavObj();

if (is_string($ids)) {
$ids_string = $ids;
/** @psalm-var list<string> $ids */
$ids = explode(self::SEPARATOR, $ids_string);
$ids = explode(self::SEPARATOR, $ids);
}

$db->startTransaction();
Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Expand Up @@ -84,7 +84,7 @@ public function __construct()
$this->admPrefs = new AdminSettings(__DIR__ . '/../config.inc.php', $this->logger, $this->httpLogger);

$rcube = rcube::get_instance();
$this->db = new Database($this->logger, $rcube->db);
$this->db = new Database($this->logger, $rcube->get_dbh());
}

public function db(): AbstractDatabase
Expand Down
6 changes: 3 additions & 3 deletions tests/DBInteroperability/DatabaseTest.php
Expand Up @@ -497,13 +497,13 @@ public function connectToDbErrFuncProvider(): array
public function testExceptionOnFailureToConnectToDb($errFunc): void
{
if ($GLOBALS["TEST_DBTYPE"] == "sqlite3") {
$dbh = \rcube_db::factory("sqlite:///" . __DIR__ . "/../../testreports/does/not/doesNotExist.db");
$dbh = \rcube_db::factory("sqlite:////does/not/doesNotExist.db");
$expErrMsg = 'doesNotExist.db';
} elseif ($GLOBALS["TEST_DBTYPE"] == "postgres") {
$dbh = \rcube_db::factory("pgsql://a@unix(" . __DIR__ . "/../../testreports/does/not/doesNotExist)/db");
$dbh = \rcube_db::factory("pgsql://a@unix(/does/not/doesNotExist)/db");
$expErrMsg = 'doesNotExist';
} elseif ($GLOBALS["TEST_DBTYPE"] == "mysql") {
$dbh = \rcube_db::factory("mysql://a@unix(" . __DIR__ . "/../../testreports/does/not/doesNotExist)/db");
$dbh = \rcube_db::factory("mysql://a@unix(/does/not/doesNotExist)/db");
$expErrMsg = 'No such file or directory';
} else {
$this->fail("unsupported DB");
Expand Down

0 comments on commit a140f57

Please sign in to comment.