Added logic to manage calendar sync error

due credentials revocation.

Now, under unauthorized error, service
enqueue an email to let the user know that he/she
need to sync again the calendar.

Change-Id: I6f26839597441e8cd65d5a1ce2d26e21843633c0
This commit is contained in:
Sebastian Marcet 2018-02-15 21:07:11 -03:00
parent 47c3b9de7e
commit 1c6acf5e0f
30 changed files with 1176 additions and 427 deletions

View File

@ -0,0 +1,44 @@
<?php namespace App\EntityPersisters;
use models\summit\CalendarSync\WorkQueue\AdminSummitEventActionSyncWorkRequest;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
class AdminSummitEventActionSyncWorkRequestPersister extends BasePersister
{
public static function persist(AdminSummitEventActionSyncWorkRequest $request){
$sql = <<<SQL
INSERT INTO AbstractCalendarSyncWorkRequest
(`Type`, IsProcessed, ProcessedDate, Created, LastEdited, ClassName)
VALUES (:Type, 0, NULL, NOW(), NOW(), 'AdminSummitEventActionSyncWorkRequest');
INSERT INTO AdminScheduleSummitActionSyncWorkRequest (ID, CreatedByID) VALUES (LAST_INSERT_ID(), :CreatedByID)
INSERT INTO AdminSummitEventActionSyncWorkRequest (ID, SummitEventID) VALUES (LAST_INSERT_ID(), :SummitEventID);
SQL;
$bindings = [
'Type' => $request->getType(),
'CreatedByID' => $request->getCreatedById(),
'SummitEventID' => $request->getSummitEventId(),
];
$types = [
'Type' => 'string',
'CreatedByID' => 'integer',
'SummitEventID' => 'integer',
];
self::insert($sql, $bindings, $types);
}
}

View File

@ -0,0 +1,54 @@
<?php namespace App\EntityPersisters;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use models\main\AssetsSyncRequest;
/**
* Class AssetSyncRequestPersister
* @package App\EntityPersisters
*/
final class AssetSyncRequestPersister extends BasePersister
{
/**
* @param AssetsSyncRequest $assets_sync_request
*/
public static function persist(AssetsSyncRequest $assets_sync_request){
$sql = <<<SQL
INSERT INTO AssetsSyncRequest
(
ClassName,
Created,
LastEdited,
`Origin`,
`Destination`,
Processed,
ProcessedDate
)
VALUES
('AssetsSyncRequest', NOW(), NOW(), :FromFile, :ToFile, 0, NULL );
SQL;
$bindings = [
'FromFile' => $assets_sync_request->getFrom(),
'ToFile' => $assets_sync_request->getTo(),
];
$types = [
'FromFile' => 'string',
'ToFile' => 'string',
];
self::insert($sql, $bindings, $types);
}
}

View File

@ -0,0 +1,29 @@
<?php namespace App\EntityPersisters;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use LaravelDoctrine\ORM\Facades\Registry;
/**
* Class BasePersister
* @package App\EntityPersisters
*/
abstract class BasePersister
{
/**
* @param string $sql
* @param array $bindings
*/
protected static function insert($sql, array $bindings, array $types){
$em = Registry::getManager('ss');
$em->getConnection()->executeUpdate($sql, $bindings, $types);
}
}

View File

@ -0,0 +1,63 @@
<?php namespace App\EntityPersisters;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use models\summit\SummitEntityEvent;
/**
* Class EntityEventPersister
* @package App\EntityPersisters
*/
final class EntityEventPersister extends BasePersister
{
/**
* @param SummitEntityEvent $entity_event
*/
public static function persist(SummitEntityEvent $entity_event){
$sql = <<<SQL
INSERT INTO SummitEntityEvent
(EntityID, EntityClassName, Type, Metadata, Created, LastEdited, OwnerID, SummitID)
VALUES (:EntityID, :EntityClassName, :Type, :Metadata, :Created, :LastEdited, :OwnerID, :SummitID)
SQL;
$bindings = [
'EntityID' => $entity_event->getEntityId(),
'EntityClassName' => $entity_event->getEntityClassName(),
'Type' => $entity_event->getType(),
'Metadata' => $entity_event->getRawMetadata(),
'Created' => $entity_event->getCreated(),
'LastEdited' => $entity_event->getLastEdited(),
'OwnerID' => $entity_event->getOwnerId(),
'SummitID' => $entity_event->getSummitId()
];
$types = [
'EntityID' => 'integer',
'EntityClassName' => 'string',
'Type' => 'string',
'Metadata' => 'string',
'Created' => 'datetime',
'LastEdited' => 'datetime',
'OwnerID' => 'integer',
'SummitID' => 'integer',
];
self::insert($sql, $bindings, $types);
}
/**
* @param SummitEntityEvent[] $entity_events
*/
public static function persist_list(array $entity_events){
foreach ($entity_events as $entity_event)
self::persist($entity_event);
}
}

View File

@ -0,0 +1,34 @@
<?php namespace App\Factories\AssetsSyncRequest;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\FileCreated;
use Illuminate\Support\Facades\Config;
use models\main\AssetsSyncRequest;
/**
* Class FileCreatedAssetSyncRequestFactory
* @package App\Factories\AssetsSyncRequest
*/
final class FileCreatedAssetSyncRequestFactory
{
public static function build(FileCreated $event){
$folder_name = $event->getFolderName();
$file_name = $event->getFileName();
$remote_base_path = Config::get('scp.scp_remote_base_path', null);
$remote_destination = sprintf("%s/%s", $remote_base_path, $file_name);
$asset_sync_request = new AssetsSyncRequest();
$asset_sync_request->setFrom($remote_destination);
$asset_sync_request->setTo(sprintf("%s/%s", $folder_name, $file_name));
$asset_sync_request->setProcessed(false);
return $asset_sync_request;
}
}

View File

@ -0,0 +1,53 @@
<?php namespace App\Factories\CalendarAdminActionSyncWorkRequest;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\SummitEventDeleted;
use models\summit\CalendarSync\WorkQueue\AbstractCalendarSyncWorkRequest;
use models\summit\CalendarSync\WorkQueue\AdminSummitEventActionSyncWorkRequest;
use Illuminate\Support\Facades\App;
/**
* Class SummitEventDeletedCalendarSyncWorkRequestFactory
* @package App\Factories\CalendarAdminActionSyncWorkRequest
*/
final class SummitEventDeletedCalendarSyncWorkRequestFactory
{
/**
* @param SummitEventDeleted $event
* @return AdminSummitEventActionSyncWorkRequest|null
*/
public static function build(SummitEventDeleted $event){
$args = $event->getArgs();
$params = $args->getParams();
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
}
$request = null;
if(isset($params['published']) && $params['published']){
// just record the published state at the moment of the update
$request = new AdminSummitEventActionSyncWorkRequest();
$request->setSummitEventId ($params['id']);
$request->setType(AbstractCalendarSyncWorkRequest::TypeRemove);
if($owner_id > 0){
$request->setCreatedBy($member);
}
}
return $request;
}
}

View File

@ -0,0 +1,53 @@
<?php namespace App\Factories\CalendarAdminActionSyncWorkRequest;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\SummitEventUpdated;
use models\summit\CalendarSync\WorkQueue\AbstractCalendarSyncWorkRequest;
use models\summit\CalendarSync\WorkQueue\AdminSummitEventActionSyncWorkRequest;
use Illuminate\Support\Facades\App;
/**
* Class SummitEventUpdatedCalendarSyncWorkRequestFactory
* @package App\Factories\CalendarAdminActionSyncWorkRequest
*/
final class SummitEventUpdatedCalendarSyncWorkRequestFactory
{
/**
* @param SummitEventUpdated $event
* @return AdminSummitEventActionSyncWorkRequest
*/
public static function build(SummitEventUpdated $event){
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$args = $event->getArgs();
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
// sync request from admin
$request = new AdminSummitEventActionSyncWorkRequest();
$request->setSummitEvent($event->getSummitEvent()) ;
$request->setType(AbstractCalendarSyncWorkRequest::TypeUpdate);
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$request->setCreatedBy($member);
}
if($args->hasChangedField('published')){
$pub_old = intval($args->getOldValue('published'));
$pub_new = intval($args->getNewValue('published'));
if($pub_old == 1 && $pub_new == 0)
$request->setType(AbstractCalendarSyncWorkRequest::TypeRemove);
}
return $request;
}
}

View File

@ -0,0 +1,36 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use models\summit\SummitEntityEvent;
use App\Events\MyFavoritesAdd;
/**
* Class MyFavoritesAddEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class MyFavoritesAddEntityEventFactory
{
/**
* @param MyFavoritesAdd $event
* @return SummitEntityEvent
*/
public static function build(MyFavoritesAdd $event){
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('MyFavorite');
$entity_event->setEntityId($event->getEventId());
$entity_event->setType('INSERT');
$entity_event->setOwner($event->getMember());
$entity_event->setSummit($event->getSummit());
$entity_event->setMetadata('');
return $entity_event;
}
}

View File

@ -0,0 +1,38 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\MyFavoritesRemove;
use models\summit\SummitEntityEvent;
/**
* Class MyFavoritesRemoveEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class MyFavoritesRemoveEntityEventFactory
{
/**
* @param MyFavoritesRemove $event
* @return SummitEntityEvent
*/
public static function build(MyFavoritesRemove $event){
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('MyFavorite');
$entity_event->setEntityId($event->getEventId());
$entity_event->setType('DELETE');
$entity_event->setOwner($event->getMember());
$entity_event->setSummit($event->getSummit());
$entity_event->setMetadata('');
return $entity_event;
}
}

View File

@ -0,0 +1,36 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\MyScheduleAdd;
use models\summit\SummitEntityEvent;
/**
* Class MyScheduleAddEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class MyScheduleAddEntityEventFactory
{
/**
* @param MyScheduleAdd $event
* @return SummitEntityEvent
*/
public static function build(MyScheduleAdd $event){
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('MySchedule');
$entity_event->setEntityId($event->getEventId());
$entity_event->setType('INSERT');
$entity_event->setOwner($event->getMember());
$entity_event->setSummit($event->getSummit());
$entity_event->setMetadata('');
return $entity_event;
}
}

View File

@ -0,0 +1,36 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\MyScheduleRemove;
use models\summit\SummitEntityEvent;
/**
* Class MyScheduleRemoveEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class MyScheduleRemoveEntityEventFactory
{
/**
* @param MyScheduleRemove $event
* @return SummitEntityEvent
*/
public static function build(MyScheduleRemove $event){
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('MySchedule');
$entity_event->setEntityId($event->getEventId());
$entity_event->setType('DELETE');
$entity_event->setOwner($event->getMember());
$entity_event->setSummit($event->getSummit());
$entity_event->setMetadata('');
return $entity_event;
}
}

View File

@ -0,0 +1,48 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\PresentationMaterialCreated;
use Illuminate\Support\Facades\App;
use models\summit\SummitEntityEvent;
/**
* Class PresentationMaterialCreatedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class PresentationMaterialCreatedEntityEventFactory
{
/**
* @param PresentationMaterialCreated $event
* @return SummitEntityEvent
*/
public static function build(PresentationMaterialCreated $event){
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent();
$entity_event->setEntityClassName($event->getMaterial()->getClassName());
$entity_event->setEntityId($event->getMaterial()->getId());
$entity_event->setType('INSERT');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit());
$entity_event->setMetadata(json_encode([ 'presentation_id' => intval($event->getMaterial()->getPresentation()->getId())]));
return $entity_event;
}
}

View File

@ -0,0 +1,48 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\PresentationMaterialDeleted;
use Illuminate\Support\Facades\App;
use models\summit\SummitEntityEvent;
/**
* Class PresentationMaterialDeletedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class PresentationMaterialDeletedEntityEventFactory
{
/**
* @param PresentationMaterialDeleted $event
* @return SummitEntityEvent
*/
public static function build(PresentationMaterialDeleted $event){
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent();
$entity_event->setEntityClassName($event->getClassName());
$entity_event->setEntityId($event->getMaterialId());
$entity_event->setType('DELETE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getPresentation()->getSummit());
return $entity_event;
}
}

View File

@ -0,0 +1,48 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\PresentationMaterialUpdated;
use Illuminate\Support\Facades\App;
use models\summit\SummitEntityEvent;
/**
* Class PresentationMaterialUpdatedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class PresentationMaterialUpdatedEntityEventFactory
{
/**
* @param PresentationMaterialUpdated $event
* @return SummitEntityEvent
*/
public static function build(PresentationMaterialUpdated $event){
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent();
$entity_event->setEntityClassName($event->getMaterial()->getClassName());
$entity_event->setEntityId($event->getMaterial()->getId());
$entity_event->setType('UPDATE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit());
$entity_event->setMetadata(json_encode([ 'presentation_id' => intval($event->getMaterial()->getPresentation()->getId())]));
return $entity_event;
}
}

View File

@ -0,0 +1,53 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\PresentationSpeakerCreated;
use Illuminate\Support\Facades\App;
use models\summit\SummitEntityEvent;
/**
* Class PresentationSpeakerCreatedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class PresentationSpeakerCreatedEntityEventFactory
{
/**
* @param PresentationSpeakerCreated $event
* @return SummitEntityEvent[]
*/
public static function build(PresentationSpeakerCreated $event){
$list = [];
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
foreach($event->getPresentationSpeaker()->getRelatedSummits() as $summit) {
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName("PresentationSpeaker");
$entity_event->setEntityId($event->getPresentationSpeaker()->getId());
$entity_event->setType('INSERT');
if ($owner_id > 0) {
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($summit);
$entity_event->setMetadata('');
$list[] = $entity_event;
}
return $list;
}
}

View File

@ -0,0 +1,56 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\PresentationSpeakerDeleted;
use Illuminate\Support\Facades\App;
use models\summit\SummitEntityEvent;
/**
* Class PresentationSpeakerDeletedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class PresentationSpeakerDeletedEntityEventFactory
{
/**
* @param PresentationSpeakerDeleted $event
* @return SummitEntityEvent[]
*/
public static function build(PresentationSpeakerDeleted $event){
$list = [];
$args = $event->getArgs();
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$params = $args->getParams();
foreach($params['summits'] as $summit) {
$entity_event = new SummitEntityEvent();
$entity_event->setEntityClassName($params['class_name']);
$entity_event->setEntityId($params['id']);
$entity_event->setType('DELETE');
if ($owner_id > 0) {
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($summit);
$entity_event->setMetadata('');
$list[] = $entity_event;
}
return $list;
}
}

View File

@ -0,0 +1,54 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\PresentationSpeakerUpdated;
use Illuminate\Support\Facades\App;
use models\summit\SummitEntityEvent;
/**
* Class PresentationSpeakerUpdatedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class PresentationSpeakerUpdatedEntityEventFactory
{
/**
* @param PresentationSpeakerUpdated $event
* @return SummitEntityEvent[]
*/
public static function build(PresentationSpeakerUpdated $event){
$list = [];
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
foreach($event->getPresentationSpeaker()->getRelatedSummits() as $summit) {
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName("PresentationSpeaker");
$entity_event->setEntityId($event->getPresentationSpeaker()->getId());
$entity_event->setType('UPDATE');
if ($owner_id > 0) {
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($summit);
$entity_event->setMetadata('');
$list[] =$entity_event;
}
return $list;
}
}

View File

@ -0,0 +1,48 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\SummitEventCreated;
use Illuminate\Support\Facades\App;
use models\summit\SummitEntityEvent;
/**
* Class SummitEventCreatedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class SummitEventCreatedEntityEventFactory
{
/**
* @param SummitEventCreated $event
* @return SummitEntityEvent
*/
public static function build(SummitEventCreated $event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent();
$entity_event->setEntityClassName($event->getSummitEvent()->getClassName());
$entity_event->setEntityId($event->getSummitEvent()->getId());
$entity_event->setType('INSERT');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getSummitEvent()->getSummit());
$entity_event->setMetadata( json_encode([ 'pub_new' => intval($event->getSummitEvent()->isPublished())]));
return $entity_event;
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\SummitEventDeleted;
use models\summit\SummitEntityEvent;
use Illuminate\Support\Facades\App;
/**
* Class SummitEventDeletedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class SummitEventDeletedEntityEventFactory
{
/**
* @param SummitEventDeleted $event
* @return SummitEntityEvent
*/
public static function build(SummitEventDeleted $event){
$args = $event->getArgs();
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$params = $args->getParams();
$entity_event = new SummitEntityEvent();
$entity_event->setEntityClassName($params['class_name']);
$entity_event->setEntityId($params['id']);
$entity_event->setType('DELETE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($params['summit']);
$entity_event->setMetadata('');
if(isset($params['published']) && $params['published']){
// just record the published state at the moment of the update
$entity_event->setMetadata( json_encode([
'pub_old' => intval($params['published']),
'pub_new' => intval($params['published'])
]));
}
return $entity_event;
}
}

View File

@ -0,0 +1,62 @@
<?php namespace App\Factories\EntityEvents;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\SummitEventUpdated;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use Illuminate\Support\Facades\App;
use models\summit\SummitEntityEvent;
/**
* Class SummitEventUpdatedEntityEventFactory
* @package App\Factories\EntityEvents
*/
final class SummitEventUpdatedEntityEventFactory
{
/**
* @param SummitEventUpdated $event
* @return SummitEntityEvent|void
*/
public static function build(SummitEventUpdated $event){
$args = $event->getArgs();
if(!$args instanceof PreUpdateEventArgs) return;
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent();
$entity_event->setEntityClassName($event->getSummitEvent()->getClassName());
$entity_event->setEntityId($event->getSummitEvent()->getId());
$entity_event->setType('UPDATE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getSummitEvent()->getSummit());
// check if there was a change on publishing state
if($args->hasChangedField('published')){
$pub_old = intval($args->getOldValue('published'));
$pub_new = intval($args->getNewValue('published'));
$metadata = json_encode([ 'pub_old'=> $pub_old, 'pub_new' => $pub_new]);
}
else
$metadata = json_encode([ 'pub_new' => intval($event->getSummitEvent()->getPublished())]);
$entity_event->setMetadata($metadata);
return $entity_event;
}
}

View File

@ -0,0 +1,46 @@
<?php namespace models\main;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\ORM\Mapping AS ORM;
use models\summit\CalendarSync\CalendarSyncInfo;
/**
* @ORM\Entity
* @ORM\Table(name="CalendarSyncErrorEmailRequest")
* Class CalendarSyncErrorEmailRequest
* @package models\main
*/
class CalendarSyncErrorEmailRequest extends EmailCreationRequest
{
/**
* @ORM\ManyToOne(targetEntity="models\summit\CalendarSync\CalendarSyncInfo")
* @ORM\JoinColumn(name="CalendarSyncInfoID", referencedColumnName="ID")
* @var CalendarSyncInfo
*/
protected $sync_info;
/**
* @return CalendarSyncInfo
*/
public function getSyncInfo()
{
return $this->sync_info;
}
/**
* @param CalendarSyncInfo $sync_info
*/
public function setSyncInfo($sync_info)
{
$this->sync_info = $sync_info;
}
}

View File

@ -22,6 +22,7 @@ use DateTime;
* @ORM\DiscriminatorMap({"EmailCreationRequest" = "EmailCreationRequest",
* "SpeakerCreationEmailCreationRequest" = "SpeakerCreationEmailCreationRequest",
* "MemberPromoCodeEmailCreationRequest"= "MemberPromoCodeEmailCreationRequest",
* "CalendarSyncErrorEmailRequest" = "CalendarSyncErrorEmailRequest",
* "SpeakerSelectionAnnouncementEmailCreationRequest" = "SpeakerSelectionAnnouncementEmailCreationRequest"})
* Class EmailCreationRequest
* @package models\main

View File

@ -11,10 +11,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use models\main\Member;
use Doctrine\ORM\Mapping AS ORM;
/**
* Class AdminScheduleSummitActionSyncWorkRequest
* @ORM\Entity
@ -46,4 +44,18 @@ class AdminScheduleSummitActionSyncWorkRequest
{
$this->created_by = $created_by;
}
/**
* @return int
*/
public function getCreatedById(){
try {
return is_null($this->created_by) ? 0 :$this->created_by->getId();
}
catch(\Exception $ex){
return 0;
}
}
}

View File

@ -11,35 +11,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\MyFavoritesAdd;
use App\Events\PresentationSpeakerCreated;
use App\Events\PresentationSpeakerDeleted;
use App\Events\PresentationSpeakerUpdated;
use App\Events\SummitEventCreated;
use App\Events\SummitEventDeleted;
use App\Events\SummitEventUpdated;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use App\EntityPersisters\AdminSummitEventActionSyncWorkRequestPersister;
use App\EntityPersisters\AssetSyncRequestPersister;
use App\EntityPersisters\EntityEventPersister;
use App\Factories\AssetsSyncRequest\FileCreatedAssetSyncRequestFactory;
use App\Factories\CalendarAdminActionSyncWorkRequest\SummitEventDeletedCalendarSyncWorkRequestFactory;
use App\Factories\CalendarAdminActionSyncWorkRequest\SummitEventUpdatedCalendarSyncWorkRequestFactory;
use App\Factories\EntityEvents\MyFavoritesAddEntityEventFactory;
use App\Factories\EntityEvents\MyFavoritesRemoveEntityEventFactory;
use App\Factories\EntityEvents\MyScheduleAddEntityEventFactory;
use App\Factories\EntityEvents\MyScheduleRemoveEntityEventFactory;
use App\Factories\EntityEvents\PresentationMaterialCreatedEntityEventFactory;
use App\Factories\EntityEvents\PresentationMaterialDeletedEntityEventFactory;
use App\Factories\EntityEvents\PresentationMaterialUpdatedEntityEventFactory;
use App\Factories\EntityEvents\PresentationSpeakerCreatedEntityEventFactory;
use App\Factories\EntityEvents\PresentationSpeakerDeletedEntityEventFactory;
use App\Factories\EntityEvents\PresentationSpeakerUpdatedEntityEventFactory;
use App\Factories\EntityEvents\SummitEventCreatedEntityEventFactory;
use App\Factories\EntityEvents\SummitEventDeletedEntityEventFactory;
use App\Factories\EntityEvents\SummitEventUpdatedEntityEventFactory;
use App\Services\Utils\SCPFileUploader;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use LaravelDoctrine\ORM\Facades\Registry;
use models\main\AssetsSyncRequest;
use models\summit\CalendarSync\WorkQueue\AbstractCalendarSyncWorkRequest;
use models\summit\CalendarSync\WorkQueue\AdminSummitEventActionSyncWorkRequest;
use models\summit\SummitEntityEvent;
use App\Events\MyScheduleAdd;
use App\Events\MyScheduleRemove;
use Doctrine\ORM\Event\PreUpdateEventArgs;
use models\utils\PreRemoveEventArgs;
use IDCT\Networking\Ssh\SftpClient;
use IDCT\Networking\Ssh\Credentials;
/**
* Class EventServiceProvider
* @package App\Providers
*/
class EventServiceProvider extends ServiceProvider
final class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
@ -52,85 +50,6 @@ class EventServiceProvider extends ServiceProvider
],
];
private static function persistsEntityEvent(SummitEntityEvent $entity_event){
$sql = <<<SQL
INSERT INTO SummitEntityEvent
(EntityID, EntityClassName, Type, Metadata, Created, LastEdited, OwnerID, SummitID)
VALUES (:EntityID, :EntityClassName, :Type, :Metadata, :Created, :LastEdited, :OwnerID, :SummitID)
SQL;
$bindings = [
'EntityID' => $entity_event->getEntityId(),
'EntityClassName' => $entity_event->getEntityClassName(),
'Type' => $entity_event->getType(),
'Metadata' => $entity_event->getRawMetadata(),
'Created' => $entity_event->getCreated(),
'LastEdited' => $entity_event->getLastEdited(),
'OwnerID' => $entity_event->getOwnerId(),
'SummitID' => $entity_event->getSummitId()
];
$types = [
'EntityID' => 'integer',
'EntityClassName' => 'string',
'Type' => 'string',
'Metadata' => 'string',
'Created' => 'datetime',
'LastEdited' => 'datetime',
'OwnerID' => 'integer',
'SummitID' => 'integer',
];
self::insert($sql, $bindings, $types);
}
private static function persistAdminSyncRequest(AdminSummitEventActionSyncWorkRequest $request){
$em = Registry::getManager('ss');
$em->persist($request);
$em->flush();
}
private static function persistsAssetSyncRequest(AssetsSyncRequest $assets_sync_request){
$sql = <<<SQL
INSERT INTO AssetsSyncRequest
(
ClassName,
Created,
LastEdited,
`Origin`,
`Destination`,
Processed,
ProcessedDate
)
VALUES
('AssetsSyncRequest', NOW(), NOW(), :FromFile, :ToFile, 0, NULL );
SQL;
$bindings = [
'FromFile' => $assets_sync_request->getFrom(),
'ToFile' => $assets_sync_request->getTo(),
];
$types = [
'FromFile' => 'string',
'ToFile' => 'string',
];
self::insert($sql, $bindings, $types);
}
/**
* @param string $sql
* @param array $bindings
*/
private static function insert($sql, array $bindings, array $types){
$em = Registry::getManager('ss');
$em->getConnection()->executeUpdate($sql, $bindings, $types);
}
/**
* Register any other events for your application.
* @return void
@ -141,377 +60,78 @@ SQL;
Event::listen(\App\Events\MyScheduleAdd::class, function($event)
{
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('MySchedule');
$entity_event->setEntityId($event->getEventId());
$entity_event->setType('INSERT');
$entity_event->setOwner($event->getMember());
$entity_event->setSummit($event->getSummit());
$entity_event->setMetadata('');
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(MyScheduleAddEntityEventFactory::build($event));
});
Event::listen(\App\Events\MyFavoritesAdd::class, function($event)
{
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('MyFavorite');
$entity_event->setEntityId($event->getEventId());
$entity_event->setType('INSERT');
$entity_event->setOwner($event->getMember());
$entity_event->setSummit($event->getSummit());
$entity_event->setMetadata('');
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(MyFavoritesAddEntityEventFactory::build($event));
});
Event::listen(\App\Events\MyScheduleRemove::class, function($event)
{
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('MySchedule');
$entity_event->setEntityId($event->getEventId());
$entity_event->setType('DELETE');
$entity_event->setOwner($event->getMember());
$entity_event->setSummit($event->getSummit());
$entity_event->setMetadata('');
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(MyScheduleRemoveEntityEventFactory::build($event));
});
Event::listen(\App\Events\MyFavoritesRemove::class, function($event)
{
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName('MyFavorite');
$entity_event->setEntityId($event->getEventId());
$entity_event->setType('DELETE');
$entity_event->setOwner($event->getMember());
$entity_event->setSummit($event->getSummit());
$entity_event->setMetadata('');
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(MyFavoritesRemoveEntityEventFactory::build($event));
});
Event::listen(\App\Events\SummitEventCreated::class, function($event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getSummitEvent()->getClassName());
$entity_event->setEntityId($event->getSummitEvent()->getId());
$entity_event->setType('INSERT');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getSummitEvent()->getSummit());
$entity_event->setMetadata( json_encode([ 'pub_new' => intval($event->getSummitEvent()->isPublished())]));
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(SummitEventCreatedEntityEventFactory::build($event));
});
Event::listen(\App\Events\SummitEventUpdated::class, function($event)
{
if(!$event instanceof SummitEventUpdated) return;
$args = $event->getArgs();
if(!$args instanceof PreUpdateEventArgs) return;
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getSummitEvent()->getClassName());
$entity_event->setEntityId($event->getSummitEvent()->getId());
$entity_event->setType('UPDATE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getSummitEvent()->getSummit());
// sync request from admin
$request = new AdminSummitEventActionSyncWorkRequest();
$request->setSummitEvent($event->getSummitEvent()) ;
$request->setType(AbstractCalendarSyncWorkRequest::TypeUpdate);
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$request->setCreatedBy($member);
}
// check if there was a change on publishing state
if($args->hasChangedField('published')){
$pub_old = intval($args->getOldValue('published'));
$pub_new = intval($args->getNewValue('published'));
$entity_event->setMetadata(json_encode([ 'pub_old'=> $pub_old, 'pub_new' => $pub_new]));
if($pub_old == 1 && $pub_new == 0)
$request->setType(AbstractCalendarSyncWorkRequest::TypeRemove);
}
else
$entity_event->setMetadata(json_encode([ 'pub_new' => intval($event->getSummitEvent()->getPublished())]));
self::persistsEntityEvent($entity_event);
self::persistAdminSyncRequest($request);
EntityEventPersister::persist(SummitEventUpdatedEntityEventFactory::build($event));
AdminSummitEventActionSyncWorkRequestPersister::persist(SummitEventUpdatedCalendarSyncWorkRequestFactory::build($event));
});
Event::listen(\App\Events\SummitEventDeleted::class, function($event)
{
if(!$event instanceof SummitEventDeleted) return;
$args = $event->getArgs();
if(!$args instanceof PreRemoveEventArgs) return;
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$params = $args->getParams();
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($params['class_name']);
$entity_event->setEntityId($params['id']);
$entity_event->setType('DELETE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($params['summit']);
$entity_event->setMetadata('');
$request = null;
if(isset($params['published']) && $params['published']){
// just record the published state at the moment of the update
$entity_event->setMetadata( json_encode([
'pub_old' => intval($params['published']),
'pub_new' => intval($params['published'])
]));
$request = new AdminSummitEventActionSyncWorkRequest();
$request->setSummitEventId ($params['id']);
$request->setType(AbstractCalendarSyncWorkRequest::TypeRemove);
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$request->setCreatedBy($member);
}
}
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(SummitEventDeletedEntityEventFactory::build($event));
$request = SummitEventDeletedCalendarSyncWorkRequestFactory::build($event);
if(!is_null($request))
self::persistAdminSyncRequest($request);
AdminSummitEventActionSyncWorkRequestPersister::persist($request);
});
Event::listen(\App\Events\PresentationMaterialCreated::class, function($event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getMaterial()->getClassName());
$entity_event->setEntityId($event->getMaterial()->getId());
$entity_event->setType('INSERT');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit());
$entity_event->setMetadata(json_encode([ 'presentation_id' => intval($event->getMaterial()->getPresentation()->getId())]));
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(PresentationMaterialCreatedEntityEventFactory::build($event));
});
Event::listen(\App\Events\PresentationMaterialUpdated::class, function($event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getMaterial()->getClassName());
$entity_event->setEntityId($event->getMaterial()->getId());
$entity_event->setType('UPDATE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit());
$entity_event->setMetadata(json_encode([ 'presentation_id' => intval($event->getMaterial()->getPresentation()->getId())]));
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(PresentationMaterialUpdatedEntityEventFactory::build(($event)));
});
Event::listen(\App\Events\PresentationMaterialDeleted::class, function($event)
{
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($event->getClassName());
$entity_event->setEntityId($event->getMaterialId());
$entity_event->setType('DELETE');
if($owner_id > 0){
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($event->getPresentation()->getSummit());
self::persistsEntityEvent($entity_event);
EntityEventPersister::persist(PresentationMaterialDeletedEntityEventFactory::build($event));
});
Event::listen(\App\Events\FileCreated::class, function($event)
{
$storage_path = storage_path();
$local_path = $event->getLocalPath();
$file_name = $event->getFileName();
$folder_name = $event->getFolderName();
$remote_base_path = Config::get('scp.scp_remote_base_path', null);
$client = new SftpClient();
$host = Config::get('scp.scp_host', null);
$credentials = Credentials::withPublicKey
(
Config::get('scp.ssh_user', null),
Config::get('scp.ssh_public_key', null),
Config::get('scp.ssh_private_key', null)
);
$client->setCredentials($credentials);
$client->connect($host);
$remote_destination = sprintf("%s/%s",$remote_base_path, $file_name);
$client->scpUpload(sprintf("%s/app/%s", $storage_path, $local_path), $remote_destination);
$client->close();
$asset_sync_request = new AssetsSyncRequest();
$asset_sync_request->setFrom($remote_destination);
$asset_sync_request->setTo(sprintf("%s/%s", $folder_name, $file_name));
$asset_sync_request->setProcessed(false);
self::persistsAssetSyncRequest($asset_sync_request);
SCPFileUploader::upload($event);
AssetSyncRequestPersister::persist(FileCreatedAssetSyncRequestFactory::build($event));
});
Event::listen(\App\Events\PresentationSpeakerCreated::class, function($event)
{
if(!$event instanceof PresentationSpeakerCreated) return;
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
foreach($event->getPresentationSpeaker()->getRelatedSummits() as $summit) {
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName("PresentationSpeaker");
$entity_event->setEntityId($event->getPresentationSpeaker()->getId());
$entity_event->setType('INSERT');
if ($owner_id > 0) {
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($summit);
$entity_event->setMetadata('');
self::persistsEntityEvent($entity_event);
}
EntityEventPersister::persist_list(PresentationSpeakerCreatedEntityEventFactory::build($event));
});
Event::listen(\App\Events\PresentationSpeakerUpdated::class, function($event)
{
if(!$event instanceof PresentationSpeakerUpdated) return;
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
foreach($event->getPresentationSpeaker()->getRelatedSummits() as $summit) {
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName("PresentationSpeaker");
$entity_event->setEntityId($event->getPresentationSpeaker()->getId());
$entity_event->setType('UPDATE');
if ($owner_id > 0) {
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($summit);
$entity_event->setMetadata('');
self::persistsEntityEvent($entity_event);
}
EntityEventPersister::persist_list(PresentationSpeakerUpdatedEntityEventFactory::build($event));
});
Event::listen(\App\Events\PresentationSpeakerDeleted::class, function($event)
{
if(!$event instanceof PresentationSpeakerDeleted) return;
$args = $event->getArgs();
if(!$args instanceof PreRemoveEventArgs) return;
$resource_server_context = App::make(\models\oauth2\IResourceServerContext::class);
$member_repository = App::make(\models\main\IMemberRepository::class);
$owner_id = $resource_server_context->getCurrentUserExternalId();
if(is_null($owner_id)) $owner_id = 0;
$params = $args->getParams();
foreach($params['summits'] as $summit) {
$entity_event = new SummitEntityEvent;
$entity_event->setEntityClassName($params['class_name']);
$entity_event->setEntityId($params['id']);
$entity_event->setType('DELETE');
if ($owner_id > 0) {
$member = $member_repository->getById($owner_id);
$entity_event->setOwner($member);
}
$entity_event->setSummit($summit);
$entity_event->setMetadata('');
self::persistsEntityEvent($entity_event);
}
EntityEventPersister::persist_list(PresentationSpeakerDeletedEntityEventFactory::build($event));
});
}

View File

@ -0,0 +1,23 @@
<?php namespace App\Services\Apis\CalendarSync\Exceptions;
/**
* Copyright 2017 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Exception;
/**
* Class RevokedAccessException
* @package App\Services\Apis\CalendarSync\Exceptions
*/
final class RevokedAccessException extends Exception
{
}

View File

@ -12,6 +12,7 @@
* limitations under the License.
**/
use App\Services\Apis\CalendarSync\Exceptions\RateLimitExceededException;
use App\Services\Apis\CalendarSync\Exceptions\RevokedAccessException;
use models\summit\CalendarSync\CalendarSyncInfo;
use models\summit\CalendarSync\CalendarSyncInfoOAuth2;
use models\summit\CalendarSync\ScheduleCalendarSyncInfo;
@ -84,6 +85,7 @@ final class GoogleCalendarSyncRemoteFacade
* @param MemberEventScheduleSummitActionSyncWorkRequest $request
* @throws RateLimitExceededException
* @throws Google_Service_Exception
* @throws RevokedAccessException
* @return ScheduleCalendarSyncInfo
*/
public function addEvent(MemberEventScheduleSummitActionSyncWorkRequest $request)
@ -113,6 +115,9 @@ final class GoogleCalendarSyncRemoteFacade
Log::error($ex1);
throw new RateLimitExceededException($ex1->getMessage(), $ex1->getCode());
}
if($ex1->getCode() == 401){
throw new RevokedAccessException($ex1->getMessage());
}
Log::warning($ex1);
return null;
}
@ -171,6 +176,7 @@ final class GoogleCalendarSyncRemoteFacade
* @param MemberEventScheduleSummitActionSyncWorkRequest $request
* @param ScheduleCalendarSyncInfo $schedule_sync_info
* @throws RateLimitExceededException
* @throws RevokedAccessException
* @throws Google_Service_Exception
* @return bool
*/
@ -193,6 +199,9 @@ final class GoogleCalendarSyncRemoteFacade
Log::error($ex1);
throw new RateLimitExceededException($ex1->getMessage(), $ex1->getCode());
}
if($ex1->getCode() == 401){
throw new RevokedAccessException($ex1->getMessage());
}
Log::warning($ex1);
return false;
}
@ -206,6 +215,7 @@ final class GoogleCalendarSyncRemoteFacade
* @param MemberEventScheduleSummitActionSyncWorkRequest $request
* @param ScheduleCalendarSyncInfo $schedule_sync_info
* @throws RateLimitExceededException
* @throws RevokedAccessException
* @throws Google_Service_Exception
* @return bool
*/
@ -235,6 +245,9 @@ final class GoogleCalendarSyncRemoteFacade
Log::error($ex1);
throw new RateLimitExceededException($ex1->getMessage(), $ex1->getCode());
}
if($ex1->getCode() == 401){
throw new RevokedAccessException($ex1->getMessage());
}
Log::warning($ex1);
return false;
}
@ -248,6 +261,7 @@ final class GoogleCalendarSyncRemoteFacade
* @param MemberCalendarScheduleSummitActionSyncWorkRequest $request
* @param CalendarSyncInfo $calendar_sync_info
* @throws RateLimitExceededException
* @throws RevokedAccessException
* @throws Google_Service_Exception
* @return bool
*/
@ -276,6 +290,9 @@ final class GoogleCalendarSyncRemoteFacade
Log::error($ex1);
throw new RateLimitExceededException($ex1->getMessage(), $ex1->getCode());
}
if($ex1->getCode() == 401){
throw new RevokedAccessException($ex1->getMessage());
}
Log::warning($ex1);
return false;
}
@ -289,6 +306,7 @@ final class GoogleCalendarSyncRemoteFacade
* @param MemberCalendarScheduleSummitActionSyncWorkRequest $request
* @param CalendarSyncInfo $calendar_sync_info
* @throws RateLimitExceededException
* @throws RevokedAccessException
* @throws Google_Service_Exception
* @return bool
*/
@ -311,6 +329,9 @@ final class GoogleCalendarSyncRemoteFacade
Log::error($ex1);
throw new RateLimitExceededException($ex1->getMessage(), $ex1->getCode());
}
if($ex1->getCode() == 401){
throw new RevokedAccessException($ex1->getMessage());
}
Log::warning($ex1);
return false;
}

View File

@ -11,8 +11,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Services\Apis\CalendarSync\Exceptions\RevokedAccessException;
use CalDAVClient\Facade\CalDavClient;
use CalDAVClient\Facade\Exceptions\ForbiddenException;
use CalDAVClient\Facade\Exceptions\UserUnAuthorizedException;
use CalDAVClient\Facade\Requests\EventRequestVO;
use CalDAVClient\Facade\Requests\MakeCalendarRequestVO;
use CalDAVClient\ICalDavClient;
@ -290,6 +292,11 @@ final class ICloudCalendarSyncRemoteFacade
$this->sync_calendar_info->setCalendarSyncToken($res->getSyncToken());
return true;
}
catch(UserUnAuthorizedException $ex1){
Log::warning($ex1);
throw new RevokedAccessException($ex1->getMessage());
return false;
}
catch (Exception $ex){
Log::error($ex);
return false;

View File

@ -246,7 +246,6 @@ final class OutlookCalendarSyncRemoteFacade
$this->sync_calendar_info->setEtag($res->getChangeKey());
return true;
}
return false;
}
catch (Exception $ex){

View File

@ -12,10 +12,13 @@
* limitations under the License.
**/
use App\Services\Apis\CalendarSync\Exceptions\RateLimitExceededException;
use App\Services\Apis\CalendarSync\Exceptions\RevokedAccessException;
use CalDAVClient\Facade\Exceptions\ForbiddenException;
use CalDAVClient\Facade\Exceptions\NotFoundResourceException;
use CalDAVClient\Facade\Exceptions\ServerErrorException;
use CalDAVClient\Facade\Exceptions\UserUnAuthorizedException;
use models\main\CalendarSyncErrorEmailRequest;
use models\main\IEmailCreationRequestRepository;
use models\summit\CalendarSync\WorkQueue\AbstractCalendarSyncWorkRequest;
use models\summit\CalendarSync\WorkQueue\MemberCalendarScheduleSummitActionSyncWorkRequest;
use models\summit\CalendarSync\WorkQueue\MemberEventScheduleSummitActionSyncWorkRequest;
@ -57,10 +60,16 @@ implements IMemberActionsCalendarSyncProcessingService
*/
private $preprocessor_requests;
/**
* @var IEmailCreationRequestRepository
*/
private $email_creation_request_repository;
/**
* MemberActionsCalendarSyncProcessingService constructor.
* @param IAbstractCalendarSyncWorkRequestRepository $work_request_repository
* @param ICalendarSyncInfoRepository $calendar_sync_repository
* @param IEmailCreationRequestRepository $email_creation_request_repository
* @param ICalendarSyncWorkRequestPreProcessor $preprocessor_requests
* @param ITransactionService $tx_manager
*/
@ -68,14 +77,16 @@ implements IMemberActionsCalendarSyncProcessingService
(
IAbstractCalendarSyncWorkRequestRepository $work_request_repository,
ICalendarSyncInfoRepository $calendar_sync_repository,
IEmailCreationRequestRepository $email_creation_request_repository,
ICalendarSyncWorkRequestPreProcessor $preprocessor_requests,
ITransactionService $tx_manager
)
{
$this->work_request_repository = $work_request_repository;
$this->calendar_sync_repository = $calendar_sync_repository;
$this->preprocessor_requests = $preprocessor_requests;
$this->tx_manager = $tx_manager;
$this->work_request_repository = $work_request_repository;
$this->calendar_sync_repository = $calendar_sync_repository;
$this->email_creation_request_repository = $email_creation_request_repository;
$this->preprocessor_requests = $preprocessor_requests;
$this->tx_manager = $tx_manager;
}
@ -215,8 +226,17 @@ implements IMemberActionsCalendarSyncProcessingService
// cant create calendar (CAL DAV)...
Log::warning($ex1);
}
catch(UserUnAuthorizedException $ex2){
catch(RevokedAccessException $ex2){
Log::warning($ex2);
if(!is_null($calendar_sync_info) && !$calendar_sync_info->isRevoked()){
// revoke it ...
$calendar_sync_info->setRevoked(true);
// create email request
$email_request = new CalendarSyncErrorEmailRequest();
$email_request->setSyncInfo($calendar_sync_info);
$this->email_creation_request_repository->add($email_request);
}
}
catch(NotFoundResourceException $ex3){
Log::error($ex3);

View File

@ -0,0 +1,47 @@
<?php namespace App\Services\Utils;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Events\FileCreated;
use IDCT\Networking\Ssh\Credentials;
use IDCT\Networking\Ssh\SftpClient;
use Illuminate\Support\Facades\Config;
/**
* Class SCPFileUploader
* @package App\Services\Utils
*/
final class SCPFileUploader
{
public static function upload(FileCreated $event){
$storage_path = storage_path();
$local_path = $event->getLocalPath();
$file_name = $event->getFileName();
$remote_base_path = Config::get('scp.scp_remote_base_path', null);
$client = new SftpClient();
$host = Config::get('scp.scp_host', null);
$credentials = Credentials::withPublicKey
(
Config::get('scp.ssh_user', null),
Config::get('scp.ssh_public_key', null),
Config::get('scp.ssh_private_key', null)
);
$client->setCredentials($credentials);
$client->connect($host);
$remote_destination = sprintf("%s/%s", $remote_base_path, $file_name);
$client->scpUpload(sprintf("%s/app/%s", $storage_path, $local_path), $remote_destination);
$client->close();
}
}