Loading module/Oscar/src/Oscar/Connector/Access/ConnectorAccessCurlHttp.php +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ class ConnectorAccessCurlHttp implements IConnectorAccess curl_setopt($curl, CURLOPT_FAILONERROR, true); // Fix CURL error curl: (18) transfer closed with 141 bytes remaining to read curl_setopt($curl, CURLOPT_IGNORE_CONTENT_LENGTH, true); //curl_setopt($curl, CURLOPT_IGNORE_CONTENT_LENGTH, true); $return = curl_exec($curl); Loading module/Oscar/src/Oscar/Connector/ConnectorPersonREST.php +26 −1 Original line number Diff line number Diff line Loading @@ -77,6 +77,12 @@ class ConnectorPersonREST extends AbstractConnector return $this->personHydrator; } protected function log( string $text ) :void { if( true ){ echo "$text"; } } /** * @param PersonRepository $personRepository * @param bool $force Loading @@ -85,15 +91,16 @@ class ConnectorPersonREST extends AbstractConnector */ function syncPersons(PersonRepository $personRepository, $force) { $exist = []; $exist = $personRepository->getUidsConnector($this->getName()); $repport = new ConnectorRepport(); $this->getPersonHydrator()->setPurge($this->getOptionPurge()); $repport->addnotice(sprintf("Il y'a déjà %s personne(s) synchronisée(s) pour le connector '%s'", count($exist), $this->getName())); $access = $this->getAccessStrategy(); $this->log("Pending access : " . count($exist)); try { $json = $access->getDataAll(); $this->log("data gain : " . count($json)); $personsDatas = null; if( is_object($json) && property_exists($json, 'persons') ){ Loading Loading @@ -176,16 +183,31 @@ class ConnectorPersonREST extends AbstractConnector if( count($personOscarToDelete->getActivities()) > 0 ){ $activeIn[] = "activité"; } if( count($personOscarToDelete->getProjectAffectations()) > 0 ){ $activeIn[] = "projet"; } // Récupération des affectations issues de la synchro $synchronizedAffectationsOrganizations = $personOscarToDelete->getOrganizationsSync(); if( count($synchronizedAffectationsOrganizations) > 0 ){ $personRepository->removeOrganizationPersons($synchronizedAffectationsOrganizations); $personRepository->flush($synchronizedAffectationsOrganizations); } if( count($personOscarToDelete->getOrganizations()) > 0 ){ $activeIn[] = "organisation"; } if( count($activeIn) == 0 ){ $idsToDelete[] = $personOscarToDelete->getId(); } else { // Tentative de suppression des rôles synchronisés $repport->addwarning("$personOscarToDelete n'a pas été supprimé car il est actif dans : " . implode(', ', $activeIn)); } Loading @@ -204,10 +226,13 @@ class ConnectorPersonREST extends AbstractConnector } } } catch (\Exception $e ){ $this->log("ERROR : " . $e->getMessage()); throw new \Exception("Impossible de synchroniser les personnes : " . $e->getMessage()); } $this->log("FLUSH..."); $personRepository->flush(null); $this->log("FLUSH DONE..."); return $repport; } Loading module/Oscar/src/Oscar/Entity/OrganizationPerson.php +5 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,11 @@ class OrganizationPerson implements ILoggable return $this; } public function isSync() { return !($this->getOrigin() == null || $this->getOrigin() == ''); } /** * @return Role */ Loading module/Oscar/src/Oscar/Entity/Person.php +58 −25 Original line number Diff line number Diff line Loading @@ -211,7 +211,8 @@ class Person implements ResourceInterface protected $customSettings; function __construct() { function __construct() { $this->projectAffectations = new ArrayCollection(); $this->activities = new ArrayCollection(); $this->organizations = new ArrayCollection(); Loading @@ -229,9 +230,12 @@ class Person implements ResourceInterface /** * Return TRUE si l'objet a un connector. */ public function isConnected( $connectors = null){ public function isConnected($connectors = null) { foreach ($this->getConnectors() as $connector => $value) { if( $connectors != null && !in_array($connector, $connectors) ) continue; if ($connectors != null && !in_array($connector, $connectors)) { continue; } if ($value) { return true; } Loading @@ -239,7 +243,8 @@ class Person implements ResourceInterface return false; } public function getConnectorsDatasStr(){ public function getConnectorsDatasStr() { $out = []; foreach ($this->getConnectors() as $connector => $value) { $out[] = sprintf("%s=%s", $connector, $value); Loading @@ -264,11 +269,13 @@ class Person implements ResourceInterface return $this; } public function getCustomSettingsObj(){ public function getCustomSettingsObj() { return json_decode($this->getCustomSettings(), JSON_OBJECT_AS_ARRAY); } public function getCustomSettingsKey( $key ){ public function getCustomSettingsKey($key) { $custom = $this->getCustomSettingsObj(); if (is_array($custom) && array_key_exists($key, $custom)) { return $custom[$key]; Loading @@ -276,7 +283,8 @@ class Person implements ResourceInterface return null; } public function setCustomSettingsObj( $datas ){ public function setCustomSettingsObj($datas) { $this->setCustomSettings(json_encode($datas)); return $this; } Loading Loading @@ -336,7 +344,8 @@ class Person implements ResourceInterface return $this; } public function getRolesFromConnector( $connectorName ){ public function getRolesFromConnector($connectorName) { return []; } Loading Loading @@ -393,8 +402,8 @@ class Person implements ResourceInterface } public function getLeadedOrganizations(){ public function getLeadedOrganizations() { $organizations = []; /** @var OrganizationPerson $organizationPerson */ Loading @@ -406,7 +415,8 @@ class Person implements ResourceInterface return $organizations; } public function isLeader(){ public function isLeader() { return count($this->getLeadedOrganizations()) > 0; } Loading @@ -418,6 +428,24 @@ class Person implements ResourceInterface return $this->organizations; } /** * Retourne uniquement les affectations (PersonOrganization) * issue de la synchronisation. * * @return OrganizationPerson[] */ public function getOrganizationsSync(): array { $syncOrganizations = []; /** @var OrganizationPerson $organizationPerson */ foreach ($this->getOrganizations() as $organizationPerson) { if( $organizationPerson->isSync() ){ $syncOrganizations[] = $organizationPerson; } } return $syncOrganizations; } /** * @param ArrayCollection $organizations */ Loading Loading @@ -662,7 +690,6 @@ class Person implements ResourceInterface } /** * @return string */ Loading Loading @@ -732,7 +759,6 @@ class Person implements ResourceInterface } /** * @return string */ Loading Loading @@ -828,7 +854,8 @@ class Person implements ResourceInterface return $this; } public function setConnector( $data ){ public function setConnector($data) { $this->connectors = $data; return $this; } Loading @@ -836,7 +863,6 @@ class Person implements ResourceInterface ////////////////////////////////////////////////////////// public function getDisplayName() { return $this->getFirstname() . ' ' . $this->getLastname(); Loading @@ -858,7 +884,8 @@ class Person implements ResourceInterface } public function hasDeclarationIn( Activity $activity ){ public function hasDeclarationIn(Activity $activity) { /** @var TimeSheet $timesheet */ foreach ($activity->getTimesheets() as $timesheet) { if ($timesheet->getPerson() == $this) { Loading Loading @@ -887,7 +914,8 @@ class Person implements ResourceInterface ); } public function toArrayList(){ public function toArrayList() { $datas = $this->toArray(); $organisations = []; /** @var OrganizationPerson $o */ Loading Loading @@ -921,8 +949,8 @@ class Person implements ResourceInterface } public function mergeTo( Person $person ){ public function mergeTo(Person $person) { $activititesWithWP = []; /** @var ProjectMember $projectMember */ Loading @@ -942,11 +970,11 @@ class Person implements ResourceInterface /** @var WorkPackagePerson $organizationPerson */ foreach ($this->getWorkPackages() as $workPackage) { $workPackage->setPerson($person); } } public function toJson( $options = []){ public function toJson($options = []) { $json = $this->toArray(); $json['urlPerson'] = array_key_exists('urlPerson', $options) ? $options['urlPerson'] : false; return $json; Loading @@ -965,21 +993,26 @@ class Person implements ResourceInterface private $cGetDateCreated; private $cGetDateUpdated; public function getDateCreatedStr(){ public function getDateCreatedStr() { if ($this->cGetDateCreated == null) { $this->cGetDateCreated = $this->getDateCreated() ? $this->getDateCreated()->format('c') : ""; } return $this->cGetDateCreated; } public function getDateUpdatedStr(){ public function getDateUpdatedStr() { if ($this->cGetDateUpdated == null) { $this->cGetDateUpdated = $this->getDateUpdated() ? $this->getDateUpdated()->format('c') : $this->getDateCreatedStr(); $this->cGetDateUpdated = $this->getDateUpdated() ? $this->getDateUpdated()->format( 'c' ) : $this->getDateCreatedStr(); } return $this->cGetDateUpdated; } public function getDateCachedStr(){ public function getDateCachedStr() { return $this->getDateUpdatedStr(); } } module/Oscar/src/Oscar/Entity/PersonRepository.php +7 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,13 @@ class PersonRepository extends EntityRepository implements IConnectedRepository { private $_cacheSelectebleRolesOrganisation; public function removeOrganizationPersons( array $organizationsRoles ):void { foreach ($organizationsRoles as $organizationsRole) { $this->getEntityManager()->remove($organizationsRole); } } public function getReferentsIdsPerson(int $person): array { Loading Loading
module/Oscar/src/Oscar/Connector/Access/ConnectorAccessCurlHttp.php +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ class ConnectorAccessCurlHttp implements IConnectorAccess curl_setopt($curl, CURLOPT_FAILONERROR, true); // Fix CURL error curl: (18) transfer closed with 141 bytes remaining to read curl_setopt($curl, CURLOPT_IGNORE_CONTENT_LENGTH, true); //curl_setopt($curl, CURLOPT_IGNORE_CONTENT_LENGTH, true); $return = curl_exec($curl); Loading
module/Oscar/src/Oscar/Connector/ConnectorPersonREST.php +26 −1 Original line number Diff line number Diff line Loading @@ -77,6 +77,12 @@ class ConnectorPersonREST extends AbstractConnector return $this->personHydrator; } protected function log( string $text ) :void { if( true ){ echo "$text"; } } /** * @param PersonRepository $personRepository * @param bool $force Loading @@ -85,15 +91,16 @@ class ConnectorPersonREST extends AbstractConnector */ function syncPersons(PersonRepository $personRepository, $force) { $exist = []; $exist = $personRepository->getUidsConnector($this->getName()); $repport = new ConnectorRepport(); $this->getPersonHydrator()->setPurge($this->getOptionPurge()); $repport->addnotice(sprintf("Il y'a déjà %s personne(s) synchronisée(s) pour le connector '%s'", count($exist), $this->getName())); $access = $this->getAccessStrategy(); $this->log("Pending access : " . count($exist)); try { $json = $access->getDataAll(); $this->log("data gain : " . count($json)); $personsDatas = null; if( is_object($json) && property_exists($json, 'persons') ){ Loading Loading @@ -176,16 +183,31 @@ class ConnectorPersonREST extends AbstractConnector if( count($personOscarToDelete->getActivities()) > 0 ){ $activeIn[] = "activité"; } if( count($personOscarToDelete->getProjectAffectations()) > 0 ){ $activeIn[] = "projet"; } // Récupération des affectations issues de la synchro $synchronizedAffectationsOrganizations = $personOscarToDelete->getOrganizationsSync(); if( count($synchronizedAffectationsOrganizations) > 0 ){ $personRepository->removeOrganizationPersons($synchronizedAffectationsOrganizations); $personRepository->flush($synchronizedAffectationsOrganizations); } if( count($personOscarToDelete->getOrganizations()) > 0 ){ $activeIn[] = "organisation"; } if( count($activeIn) == 0 ){ $idsToDelete[] = $personOscarToDelete->getId(); } else { // Tentative de suppression des rôles synchronisés $repport->addwarning("$personOscarToDelete n'a pas été supprimé car il est actif dans : " . implode(', ', $activeIn)); } Loading @@ -204,10 +226,13 @@ class ConnectorPersonREST extends AbstractConnector } } } catch (\Exception $e ){ $this->log("ERROR : " . $e->getMessage()); throw new \Exception("Impossible de synchroniser les personnes : " . $e->getMessage()); } $this->log("FLUSH..."); $personRepository->flush(null); $this->log("FLUSH DONE..."); return $repport; } Loading
module/Oscar/src/Oscar/Entity/OrganizationPerson.php +5 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,11 @@ class OrganizationPerson implements ILoggable return $this; } public function isSync() { return !($this->getOrigin() == null || $this->getOrigin() == ''); } /** * @return Role */ Loading
module/Oscar/src/Oscar/Entity/Person.php +58 −25 Original line number Diff line number Diff line Loading @@ -211,7 +211,8 @@ class Person implements ResourceInterface protected $customSettings; function __construct() { function __construct() { $this->projectAffectations = new ArrayCollection(); $this->activities = new ArrayCollection(); $this->organizations = new ArrayCollection(); Loading @@ -229,9 +230,12 @@ class Person implements ResourceInterface /** * Return TRUE si l'objet a un connector. */ public function isConnected( $connectors = null){ public function isConnected($connectors = null) { foreach ($this->getConnectors() as $connector => $value) { if( $connectors != null && !in_array($connector, $connectors) ) continue; if ($connectors != null && !in_array($connector, $connectors)) { continue; } if ($value) { return true; } Loading @@ -239,7 +243,8 @@ class Person implements ResourceInterface return false; } public function getConnectorsDatasStr(){ public function getConnectorsDatasStr() { $out = []; foreach ($this->getConnectors() as $connector => $value) { $out[] = sprintf("%s=%s", $connector, $value); Loading @@ -264,11 +269,13 @@ class Person implements ResourceInterface return $this; } public function getCustomSettingsObj(){ public function getCustomSettingsObj() { return json_decode($this->getCustomSettings(), JSON_OBJECT_AS_ARRAY); } public function getCustomSettingsKey( $key ){ public function getCustomSettingsKey($key) { $custom = $this->getCustomSettingsObj(); if (is_array($custom) && array_key_exists($key, $custom)) { return $custom[$key]; Loading @@ -276,7 +283,8 @@ class Person implements ResourceInterface return null; } public function setCustomSettingsObj( $datas ){ public function setCustomSettingsObj($datas) { $this->setCustomSettings(json_encode($datas)); return $this; } Loading Loading @@ -336,7 +344,8 @@ class Person implements ResourceInterface return $this; } public function getRolesFromConnector( $connectorName ){ public function getRolesFromConnector($connectorName) { return []; } Loading Loading @@ -393,8 +402,8 @@ class Person implements ResourceInterface } public function getLeadedOrganizations(){ public function getLeadedOrganizations() { $organizations = []; /** @var OrganizationPerson $organizationPerson */ Loading @@ -406,7 +415,8 @@ class Person implements ResourceInterface return $organizations; } public function isLeader(){ public function isLeader() { return count($this->getLeadedOrganizations()) > 0; } Loading @@ -418,6 +428,24 @@ class Person implements ResourceInterface return $this->organizations; } /** * Retourne uniquement les affectations (PersonOrganization) * issue de la synchronisation. * * @return OrganizationPerson[] */ public function getOrganizationsSync(): array { $syncOrganizations = []; /** @var OrganizationPerson $organizationPerson */ foreach ($this->getOrganizations() as $organizationPerson) { if( $organizationPerson->isSync() ){ $syncOrganizations[] = $organizationPerson; } } return $syncOrganizations; } /** * @param ArrayCollection $organizations */ Loading Loading @@ -662,7 +690,6 @@ class Person implements ResourceInterface } /** * @return string */ Loading Loading @@ -732,7 +759,6 @@ class Person implements ResourceInterface } /** * @return string */ Loading Loading @@ -828,7 +854,8 @@ class Person implements ResourceInterface return $this; } public function setConnector( $data ){ public function setConnector($data) { $this->connectors = $data; return $this; } Loading @@ -836,7 +863,6 @@ class Person implements ResourceInterface ////////////////////////////////////////////////////////// public function getDisplayName() { return $this->getFirstname() . ' ' . $this->getLastname(); Loading @@ -858,7 +884,8 @@ class Person implements ResourceInterface } public function hasDeclarationIn( Activity $activity ){ public function hasDeclarationIn(Activity $activity) { /** @var TimeSheet $timesheet */ foreach ($activity->getTimesheets() as $timesheet) { if ($timesheet->getPerson() == $this) { Loading Loading @@ -887,7 +914,8 @@ class Person implements ResourceInterface ); } public function toArrayList(){ public function toArrayList() { $datas = $this->toArray(); $organisations = []; /** @var OrganizationPerson $o */ Loading Loading @@ -921,8 +949,8 @@ class Person implements ResourceInterface } public function mergeTo( Person $person ){ public function mergeTo(Person $person) { $activititesWithWP = []; /** @var ProjectMember $projectMember */ Loading @@ -942,11 +970,11 @@ class Person implements ResourceInterface /** @var WorkPackagePerson $organizationPerson */ foreach ($this->getWorkPackages() as $workPackage) { $workPackage->setPerson($person); } } public function toJson( $options = []){ public function toJson($options = []) { $json = $this->toArray(); $json['urlPerson'] = array_key_exists('urlPerson', $options) ? $options['urlPerson'] : false; return $json; Loading @@ -965,21 +993,26 @@ class Person implements ResourceInterface private $cGetDateCreated; private $cGetDateUpdated; public function getDateCreatedStr(){ public function getDateCreatedStr() { if ($this->cGetDateCreated == null) { $this->cGetDateCreated = $this->getDateCreated() ? $this->getDateCreated()->format('c') : ""; } return $this->cGetDateCreated; } public function getDateUpdatedStr(){ public function getDateUpdatedStr() { if ($this->cGetDateUpdated == null) { $this->cGetDateUpdated = $this->getDateUpdated() ? $this->getDateUpdated()->format('c') : $this->getDateCreatedStr(); $this->cGetDateUpdated = $this->getDateUpdated() ? $this->getDateUpdated()->format( 'c' ) : $this->getDateCreatedStr(); } return $this->cGetDateUpdated; } public function getDateCachedStr(){ public function getDateCachedStr() { return $this->getDateUpdatedStr(); } }
module/Oscar/src/Oscar/Entity/PersonRepository.php +7 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,13 @@ class PersonRepository extends EntityRepository implements IConnectedRepository { private $_cacheSelectebleRolesOrganisation; public function removeOrganizationPersons( array $organizationsRoles ):void { foreach ($organizationsRoles as $organizationsRole) { $this->getEntityManager()->remove($organizationsRole); } } public function getReferentsIdsPerson(int $person): array { Loading