Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a14fb146 authored by Arnau Vàzquez's avatar Arnau Vàzquez
Browse files

Merge branch 'fix-mailbox-mapper-error' into 'nc22'

Check SQL raw backend config validity

See merge request e/infra/ecloud/nextcloud-apps/ecloud-drop-account!17
parents c476581b dbdd074c
Loading
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -6,11 +6,10 @@ use OCP\IConfig;
use OCP\ILogger;
use OCA\EcloudAccounts\Exception\DbConnectionParamsException;
use Doctrine\DBAL\DriverManager;
use Exception;
use Throwable;

class MailboxMapper
{

    private $config;
    private $conn;
    private $logger;
@@ -22,22 +21,35 @@ class MailboxMapper
        $this->initConnection();
    }

    private function initConnection() {
    private function initConnection()
    {
        try {
            $params = $this->getConnectionParams();
            $this->conn = DriverManager::getConnection($params);
        }
        catch(Exception $e) {
        } catch (Throwable $e) {
            $this->logger->info('Error connecting to SQL raw backend: ' . $e->getMessage());
        }
    }

    private function isDbConfigValid($config) : bool
    {
        if (!$config || !is_array($config)) {
            return false;
        }
        return isset($config['db_name'])
            && isset($config['mariadb_charset'])
            && isset($config['db_user'])
            && isset($config['db_password'])
            && isset($config['db_host'])
            && isset($config['db_port']) ;
    }

    private function getConnectionParams()
    {
        $config = $this->config->getSystemValue('user_backend_sql_raw');
        
        if (!$config) {
            throw new DbConnectionParamsException('Database connection params for mailbox not available in config.php!');
        if (!$this->isDbConfigValid($config)) {
            throw new DbConnectionParamsException('Invalid SQL raw configuration!');
        }

        $params = [
+6 −3
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ use OCA\EcloudAccounts\AppInfo\Application;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\ILogger;
use OCP\IConfig;
use OCP\User\Events\BeforeUserDeletedEvent;
use OCA\EcloudAccounts\Service\LDAPConnectionService;

@@ -18,11 +19,13 @@ require_once 'curl.class.php';
class BeforeUserDeletedListener implements IEventListener
{
    private $logger;
    private $config;
    private $LDAPConnectionService;

    public function __construct(ILogger $logger, LDAPConnectionService $LDAPConnectionService)
    public function __construct(ILogger $logger, IConfig $config, LDAPConnectionService $LDAPConnectionService)
    {
        $this->logger = $logger;
        $this->config = $config;
        $this->LDAPConnectionService = $LDAPConnectionService;
    }

@@ -71,9 +74,9 @@ class BeforeUserDeletedListener implements IEventListener
     */
    public function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret, string $email, bool $isUserOnLDAP = false)
    {
        $endpoint = 'postDelete.php';
        $endpoint = '/postDelete.php';
        if ($isUserOnLDAP) {
            $endpoint = 'postDeleteLDAP.php';
            $endpoint = '/postDeleteLDAP.php';
        }
        $postDeleteUrl = "https://" . $welcomeDomain . $endpoint;
        $curl = new Curl();