Commit 2a4fba36 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Travaux de réorganisation du code pour les connectors (Person/Organization)

parent d159fb42
Loading
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ abstract class AbstractConnector implements IConnector
    private $options;

    /** @var array Configuration du connecteur (issue du YAML) */
    private $config;
    protected $config;

    /** @var string Emplacement de la configuration */
    private $configFilepath;
@@ -106,10 +106,14 @@ abstract class AbstractConnector implements IConnector
     * @param ServiceManager $sm
     * @param $configFilePath
     */
    public function init( ServiceManager $sm, string $configPath, string $shortName) :void
    public function init( ServiceManager $sm, string|array $configPath, string $shortName) :void
    {
        $this->serviceManager = $sm;
        if( is_string($configPath) ){
            $this->loadParameters($configPath);
        } else {
            $this->config = $configPath;
        }
        $this->connectorName = $shortName;
    }

+60 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Connector\Access;

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Logging\Driver;
use Monolog\Logger;
use Oscar\Connector\IConnector;
use Oscar\Exception\OscarException;

class ConnectorOracle implements IConnectorAccess
{
    private array $params;

    private $connection = null;
    private Logger $logger;

    /**
     * @param array $params
     */
    public function __construct(array $params, Logger $logger)
    {
        $this->params = $params;
        $this->logger = $logger;
    }

    public function connect()
    {
        if( $this->connection === null ){
            try {
                $this->connection = DriverManager::getConnection($this->params);
            } catch (\Exception $e) {
                $this->logger->critical($e->getMessage());
                throw new OscarException("Connection ORACLE failed");
            }
        }
        return $this->connection;
    }


    public function getDatas($url)
    {
        // TODO: Implement getDatas() method.
    }

    public function getConnector(): IConnector
    {
        // TODO: Implement getConnector() method.
    }

    public function getDataSingle($remoteId, $params = null)
    {
        // TODO: Implement getDataSingle() method.
    }

    public function getDataAll($params = null)
    {
        // TODO: Implement getDataAll() method.
    }
}
 No newline at end of file
+97 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Connector;

use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Oscar\Entity\Organization;
use Oscar\Entity\OrganizationRepository;
use Oscar\Exception\OscarException;

class ConnectorOrganizationOctopus extends AbstractConnector
{
    private bool $editable = false;

    private $repport;

    private $connection;

    public function isEditable(): bool
    {
        return $this->editable;
    }

    public function setEditable(bool $editable): self
    {
        return $this;
    }

    /**
     * @return OrganizationRepository
     */
    public function getRepository()
    {
        return $this->getServiceLocator()->get(EntityManager::class)->getRepository(Organization::class);
    }


    protected function getConnection() {
        if( $this->connection === null ){
            try {
                $params = $this->getServicemanager()->get('Config')['doctrine']['connection'][$this->config['connection']]['params'];
                if( !$params ){
                    throw new OscarException("Paramètres de connexion OCTOPUS incorrects / mal renseigné");
                }
                $this->connection = DriverManager::getConnection($params);
                if( !$this->connection->connect() ){
                    throw new OscarException("Erreur de connexion à OCTOPUS (connect a retourné FALSE)");
                }
            } catch (\Exception $e){
                $this->getLogger()->critical($e->getMessage());
                $this->getLogger()->debug($e->getTraceAsString());
                throw new OscarException("Problème de connexion à OCTOPUS");
            }
        }
        return $this->connection;
    }

    /**
     * @param bool $force
     * @return ConnectorRepport
     * @throws OscarException
     */
    public function execute( bool $force = false) :ConnectorRepport
    {
        $personRepository = $this->getRepository();
        $c = $this->getConnection();
        $datas = $c->executeQuery('SELECT * FROM v_oscar_structure');
        foreach ($datas->fetchAllAssociative() as $data) {
            var_dump($data); die();
        }


        die("ICI");
        return $this->syncAll($personRepository, $force);
    }

    function getRemoteID()
    {
        // TODO: Implement getRemoteID() method.
    }

    function getRemoteFieldname($oscarFieldName)
    {
        // TODO: Implement getRemoteFieldname() method.
    }

    public function getPathAll(): string
    {
        throw new OscarException("getPathAll() not yet implemented");
    }

    public function getPathSingle($remoteId): string
    {
        throw new OscarException("getPathSingle($remoteId) not yet implemented");
        // TODO: Implement getPathSingle() method.
    }
}
 No newline at end of file
+44 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Strategy\Connector\Access;

use Doctrine\DBAL\DriverManager;
use Monolog\Logger;
use Oscar\Connector\Access\IConnectorAccess;
use Oscar\Connector\IConnector;
use Oscar\Exception\OscarException;

class AccessOracle implements IAccessConnector
{
    private array $params;

    private $connection = null;

    private Logger $logger;

    public function __construct()
    {
    }

    public function configure(array $params, Logger $logger): void
    {
        $this->params = $params;
        $this->logger = $logger;
    }

    public function connect()
    {
        if ($this->connection === null) {
            try {
                $this->connection = DriverManager::getConnection($this->params);
                if( !$this->connection ){
                    throw new OscarException('Connection ORACLE failed');
                }
            } catch (\Exception $e) {
                $this->logger->critical($e->getMessage());
                throw new OscarException("Connection ORACLE failed " . $e->getCode());
            }
        }
        return $this->connection;
    }
}
 No newline at end of file
+15 −0
Original line number Diff line number Diff line
<?php

namespace Oscar\Strategy\Connector\Access;

use Monolog\Logger;

interface IAccessConnector
{
    /**
     * @param array $params Paramètres utiles pour se connecter à la source
     * @param Logger $logger Le Logger pour tracer les erreurs
     * @return void
     */
    public function configure(array $params, Logger $logger) :void;
}
 No newline at end of file
Loading