Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Namespace all PHP files #9481

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/browser_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ jobs:
run: composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress --optimize-autoloader

- name: Execute tests
run: .github/run.sh
run: .github/run.sh || (cat logs/errors.log && exit 1)
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
run: cp .github/config-test.inc.php config/config-test.inc.php

- name: Execute tests (highest)
run: vendor/bin/phpunit -c tests/phpunit.xml --fail-on-warning --fail-on-risky
run: vendor/bin/phpunit -c tests/phpunit.xml --fail-on-warning --fail-on-risky || (cat logs/errors.log && exit 1)

- name: Upload artifacts
uses: actions/upload-artifact@master
Expand All @@ -60,7 +60,7 @@ jobs:
run: composer update --prefer-dist --prefer-stable --prefer-lowest --no-interaction --no-progress --optimize-autoloader

- name: Execute tests (lowest)
run: vendor/bin/phpunit -c tests/phpunit.xml --fail-on-warning --fail-on-risky
run: vendor/bin/phpunit -c tests/phpunit.xml --fail-on-warning --fail-on-risky || (cat logs/errors.log && exit 1)

tests_windows:
runs-on: windows-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ composer.phar
composer.lock
vendor

.phpunit.result.cache

# javascript dependencies
plugins/enigma/openpgp.min.js
plugins/managesieve/codemirror/
Expand Down
4 changes: 3 additions & 1 deletion bin/cleandb.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

namespace Roundcube\WIP;

/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
Expand Down Expand Up @@ -28,4 +30,4 @@ if (!empty($_SERVER['argv'][1])) {
$days = 7;
}

rcmail_utils::db_clean($days);
\rcmail_utils::db_clean($days);
4 changes: 3 additions & 1 deletion bin/decrypt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

namespace Roundcube\WIP;

/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
Expand Down Expand Up @@ -59,7 +61,7 @@ if ($argc < 2) {
exit('Usage: ' . basename($argv[0]) . " encrypted-hdr-part [encrypted-hdr-part ...]\n");
}

$RCMAIL = rcube::get_instance();
$RCMAIL = \rcube::get_instance();

for ($i = 1; $i < $argc; $i++) {
printf("%s\n", $RCMAIL->decrypt($argv[$i]));
Expand Down
10 changes: 6 additions & 4 deletions bin/deluser.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

namespace Roundcube\WIP;

/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
Expand Down Expand Up @@ -41,10 +43,10 @@ function _die($msg, $usage = false)
exit(1);
}

$rcmail = rcube::get_instance();
$rcmail = \rcube::get_instance();

// get arguments
$args = rcube_utils::get_opt(['h' => 'host', 'a' => 'age', 'd' => 'dry-run:bool']);
$args = \rcube_utils::get_opt(['h' => 'host', 'a' => 'age', 'd' => 'dry-run:bool']);

if (!empty($args['age']) && ($age = intval($args['age']))) {
$db = $rcmail->get_dbh();
Expand All @@ -66,7 +68,7 @@ if (!empty($args['age']) && ($age = intval($args['age']))) {
exit(0);
}

$hostname = rcmail_utils::get_host($args);
$hostname = \rcmail_utils::get_host($args);
$username = isset($args[0]) ? trim($args[0]) : null;

if (empty($username)) {
Expand All @@ -83,7 +85,7 @@ if (!$db->is_connected() || $db->is_error()) {
}

// find user in local database
$user = rcube_user::query($username, $hostname);
$user = \rcube_user::query($username, $hostname);

if (!$user) {
exit("User not found.\n");
Expand Down
4 changes: 3 additions & 1 deletion bin/gc.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

namespace Roundcube\WIP;

/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
Expand All @@ -22,7 +24,7 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/');

require INSTALL_PATH . 'program/include/clisetup.php';

$rcmail = rcube::get_instance();
$rcmail = \rcube::get_instance();

$session_driver = $rcmail->config->get('session_storage', 'db');
$session_lifetime = $rcmail->config->get('session_lifetime', 0) * 60 * 2;
Expand Down
38 changes: 20 additions & 18 deletions bin/identity.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

namespace Roundcube\WIP;

/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
Expand All @@ -22,7 +24,7 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/');

require INSTALL_PATH . 'program/include/clisetup.php';

$options = rcube_utils::get_opt([
$options = \rcube_utils::get_opt([
'u' => 'username',
'e' => 'email',
'n' => 'name',
Expand Down Expand Up @@ -80,15 +82,15 @@ function get_identity_attr($options)
$identity = $user->get_identity($identity_id);

if (empty($identity)) {
rcube::raise_error('Invalid identity ID.', false, true);
\rcube::raise_error('Invalid identity ID.', false, true);
}

if (isset($identity[$attribute])) {
$attrValue = $identity[$attribute];

echo "{$attrValue}\n";
} else {
rcube::raise_error('Invalid attribute name. Available attributes: identity_id, user_id, changed, del, standard, name, '
\rcube::raise_error('Invalid attribute name. Available attributes: identity_id, user_id, changed, del, standard, name, '
. 'organization, email, reply-to, bcc, signature, html_signature.', false, true);
}
}
Expand All @@ -114,7 +116,7 @@ function delete_identity($options)
$identities_level = get_identities_level();

if ($identities_level > 1) {
rcube::raise_error("Identities level doesn't allow this action.", false, true);
\rcube::raise_error("Identities level doesn't allow this action.", false, true);
}

if (count($options) === 1) {
Expand All @@ -133,7 +135,7 @@ function delete_identity($options)
$identity = $user->delete_identity($identity_id);

if (!$identity) {
rcube::raise_error('Invalid identity ID.');
\rcube::raise_error('Invalid identity ID.');
exit;
}

Expand All @@ -145,7 +147,7 @@ function add_identity($options)
$identities_level = get_identities_level();

if ($identities_level > 1) {
rcube::raise_error("Identities level doesn't allow this action.", false, true);
\rcube::raise_error("Identities level doesn't allow this action.", false, true);
}

if (count($options) === 1) {
Expand Down Expand Up @@ -207,7 +209,7 @@ function update_identity($options)
$identities_level = get_identities_level();

if ($identities_level > 1) {
rcube::raise_error("Identities level doesn't allow this action.", false, true);
\rcube::raise_error("Identities level doesn't allow this action.", false, true);
}

if (count($options) === 1) {
Expand Down Expand Up @@ -260,7 +262,7 @@ function update_identity($options)

if ($email !== null) {
if ($identities_level > 0) {
rcube::raise_error("Identities level doesn't allow setting email.", false, true);
\rcube::raise_error("Identities level doesn't allow setting email.", false, true);
}

$updated_identity['email'] = $email;
Expand All @@ -279,15 +281,15 @@ function update_identity($options)
}

if (count($updated_identity) === 0) {
rcube::raise_error('No attributes changed. Set some new values.', false, true);
\rcube::raise_error('No attributes changed. Set some new values.', false, true);
}

$user = get_user($options);

$identity = $user->update_identity($identity_id, $updated_identity);

if (!$identity) {
rcube::raise_error('Identity not updated. Either the identity id is incorrect or provided values are invalid.', false, true);
\rcube::raise_error('Identity not updated. Either the identity id is incorrect or provided values are invalid.', false, true);
}

if ($setAsDefault) {
Expand All @@ -314,7 +316,7 @@ function get_option_value($options, $key, $fallback, $isBoolean, $isMandatory, $
}

if ($isMandatory) {
rcube::raise_error($message, false, true);
\rcube::raise_error($message, false, true);
}

return $fallback;
Expand All @@ -323,14 +325,14 @@ function get_option_value($options, $key, $fallback, $isBoolean, $isMandatory, $
function validate_email($email, $fieldName)
{
if (!filter_var($email, \FILTER_VALIDATE_EMAIL)) {
rcube::raise_error("invalid {$fieldName} format", false, true);
\rcube::raise_error("invalid {$fieldName} format", false, true);
}
}

function validate_boolean($value, $fieldName)
{
if (!is_bool($value) && $value !== '0' && $value !== '1') {
rcube::raise_error("{$fieldName} can either be set to 1 (true), 0 (false) or without a value (true)", false, true);
\rcube::raise_error("{$fieldName} can either be set to 1 (true), 0 (false) or without a value (true)", false, true);
}
}

Expand Down Expand Up @@ -363,26 +365,26 @@ function echo_shared_options()

function get_user($options)
{
$rcmail = rcube::get_instance();
$rcmail = \rcube::get_instance();

$db = $rcmail->get_dbh();

$username = get_option_value($options, 'username', '', false, true, 'Enter the username e.g. -u [email protected]');
$host = rcmail_utils::get_host($options);
$host = \rcmail_utils::get_host($options);

// find user in local database
$user = rcube_user::query($username, $host);
$user = \rcube_user::query($username, $host);

if (empty($user)) {
rcube::raise_error("User does not exist: {$username}", false, true);
\rcube::raise_error("User does not exist: {$username}", false, true);
}

return $user;
}

function get_identities_level()
{
$rcmail = rcube::get_instance();
$rcmail = \rcube::get_instance();
$identities_level = intval($rcmail->config->get('identities_level', 0));

return $identities_level;
Expand Down
4 changes: 3 additions & 1 deletion bin/indexcontacts.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

namespace Roundcube\WIP;

/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
Expand All @@ -24,4 +26,4 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/');
require_once INSTALL_PATH . 'program/include/clisetup.php';
ini_set('memory_limit', -1);

rcmail_utils::indexcontacts();
\rcmail_utils::indexcontacts();
14 changes: 8 additions & 6 deletions bin/initdb.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

namespace Roundcube\WIP;

/*
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
Expand All @@ -24,25 +26,25 @@ define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/');
require_once INSTALL_PATH . 'program/include/clisetup.php';

// get arguments
$opts = rcube_utils::get_opt([
$opts = \rcube_utils::get_opt([
'd' => 'dir',
'u' => 'update',
]);

if (empty($opts['dir'])) {
rcube::raise_error('Database schema directory not specified (--dir).', false, true);
\rcube::raise_error('Database schema directory not specified (--dir).', false, true);
}

// Check if directory exists
if (!file_exists($opts['dir'])) {
rcube::raise_error("Specified database schema directory doesn't exist.", false, true);
\rcube::raise_error("Specified database schema directory doesn't exist.", false, true);
}

$db = rcmail_utils::db();
$db = \rcmail_utils::db();

if (!empty($opts['update']) && in_array($db->table_name('system'), (array) $db->list_tables())) {
echo 'Checking for database schema updates...' . \PHP_EOL;
rcmail_utils::db_update($opts['dir'], 'roundcube', null, ['errors' => true]);
\rcmail_utils::db_update($opts['dir'], 'roundcube', null, ['errors' => true]);
} else {
rcmail_utils::db_init($opts['dir']);
\rcmail_utils::db_init($opts['dir']);
}
Loading