Listen the onBeforeDeleteLanguageCommit event to delete the source object to the new language

@param  BeforeDeleteLanguageCommitEvent $event
@throws Exception
557110
public function onBeforeDeleteLanguageCommit(BeforeDeleteLanguageCommitEvent $event)
    {
        if ($event->isAborted()) {
            return;
        }

        $this->languageManager = $event->getContentManager();
        $languageRepository = $this->languageManager->getLanguageRepository();

        $this->sourceObjects = $this->setUpSourceObjects();
        if (null === $this->sourceObjects) {
            return;
        }

        if (count($this->sourceObjects) > 0) {
            try {
                $result = true;
                $languageRepository->startTransaction();
                foreach ($this->sourceObjects as $sourceObject) {
                    $result = $this->delete($sourceObject);
                    if (!$result) {
                        break;
                    }
                }

                if (false !== $result) {
                    $languageRepository->commit();
                } else {
                    $languageRepository->rollBack();

                    $event->abort();
                }
            } catch (\Exception $e) {
                $event->abort();
                if (isset($languageRepository) && $languageRepository !== null) {
                    $languageRepository->rollBack();
                }

                throw $e;
            }
        }
    }
1149237
public function handlePreRemove(RemoveEvent $event)
    {
        $document = $event->getDocument();

        if (!$this->supports($document)) {
            return;
        }

        $event = $this->getDeleteEvent($document);
        $this->deleteEvents[spl_object_hash($document)] = $event;
        $this->eventDispatcher->dispatch(
            ContentEvents::NODE_PRE_DELETE,
            $event
        );
    }
425609
public function delete()
    {
        if (null === $this->alLanguage) {
            throw new General\ArgumentIsEmptyException('exception_no_languages_selected_delete_skipped');
        }

        if ($this->alLanguage->getMainLanguage() == 1) {
            throw new LanguageException\RemoveMainLanguageException('exception_website_main_languages_cannot_be_delete');
        }

        $this->dispatchBeforeOperationEvent(
                '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Language\BeforeLanguageDeletingEvent',
                LanguageEvents::BEFORE_DELETE_LANGUAGE,
                array(),
                'exception_language_deleting_aborted'
        );

        try {
            $this->languageRepository->startTransaction();
            $result = $this->languageRepository
                            ->setRepositoryObject($this->alLanguage)
                            ->delete();

            if ($result) {
                $eventName = LanguageEvents::BEFORE_DELETE_LANGUAGE_COMMIT;
                $result = !$this->eventsHandler
                                ->createEvent($eventName, '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Language\BeforeDeleteLanguageCommitEvent', array($this, array()))
                                ->dispatch()
                                ->getEvent($eventName)
                                ->isAborted();
            }

            if (false !== $result) {
                $this->languageRepository->commit();

                $this->eventsHandler
                     ->createEvent(LanguageEvents::AFTER_DELETE_LANGUAGE, '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Language\AfterLanguageDeletedEvent', array($this))
                     ->dispatch();

                return $result;
            }

            $this->languageRepository->rollBack();

            return $result;
        } catch (\Exception $e) {
            if (isset($this->languageRepository) && $this->languageRepository !== null) {
                $this->languageRepository->rollBack();
            }

            throw $e;
        }
    }
994704
public function onPreExecute(Event\PreExecuteEvent $event)
    {
        $task = $event->getTask();

        if (!($task instanceof AbstractTask) || !($task instanceof ExecuteTask)) {
            return;
        }

        if (!$task->hasParameter('remote')) {
            return;
        }



        $event->stopPropagation();

        $remote = $task->getParameter('remote');
        if (!isset($this->hosts[$remote])) {
            throw new \Exception(
                sprintf(
                    "The given host (%s) doesn't exist. Must be one of: %s",
                    $remote,
                    implode(array_keys($this->hosts))
                )
            );
        }

        $ssh    = $this->createSSHHandler($this->hosts[$remote]);
        $output = $ssh->exec($event->getProcessBuilder()->getProcess()->getCommandLine());
        if ($this->output->getVerbosity() === OutputInterface::VERBOSITY_VERY_VERBOSE) {
            $this->output->writeln(
                [
                    "<comment>------Remote------</comment>",
                    $output,
                    "<comment>-----/Remote------</comment>"
                ]
            );
        }
    }
566361
public function preDelete(DeleteEvent $event)
    {
        $announcement = $event->getObject();
        $send = $this->om->getRepository(AnnouncementSend::class)->findBy(['announcement' => $announcement]);

        foreach ($send as $el) {
            $this->om->remove($el);
        }

        // delete scheduled task is any
        $this->manager->unscheduleMessage($announcement);

        $this->eventDispatcher->dispatch(
            'log',
            'Claroline\\AnnouncementBundle\\Event\\Log\\LogAnnouncementDeleteEvent',
            [$announcement->getAggregate(), $announcement]
        );
    }
451026
public function onBeforeSend(Event $event)
    {
        global $logger;
        $req        = $event['request'];
        $options    = $this->_options;
        $algorithms = array(
            'sha1',
            'sha256',
            'sha512'
        );

        if(empty($options['key']))
            $options['key'] = $this->_app->getConfiguration()->getSharedKey();
        if(empty($options['secret']))
            $options['secret'] = $this->_app->getConfiguration()->getSecretKey();

        if (!isset($options['key']) || !is_string($options['key']))
            throw new \Exception("options.key must be a String");
        if (isset($options['algorithm']) && !is_string($options['algorithm']))
            throw new \Exception("options.algorithm must be a String");
        if (isset($options['headers']) && !is_array($options['headers']))
            throw new \Exception("options.headers must be an array of Strings");

        $reqDate = $this->_rfc1123();
        if ($req->getHeader('date') === null) {
            $req->setHeader('Date', $reqDate); 
        }

        if (!isset($options['headers'])) {
            $options['headers'] = array(); 
        } 
        
        if (!in_array('Date', $options['headers'])) {
            $options['headers'][]= 'Date'; 
        }
        if (!in_array('X-Hmac-Nonce', $options['headers'])) {
            $options['headers'][]= 'X-Hmac-Nonce'; 
        }
        $req->setHeader('X-HMAC-Date', $reqDate); 
        $req->setHeader('X-HMAC-Nonce', 'Thohn2Mohd2zugoo');

        $headersToSign = array();
        foreach($options['headers'] as $hdr) {
            $headersToSign[$hdr] = $req->getHeader($hdr); 
        } 
        
        if (!isset($options['algorithm']))
            $options['algorithm'] = 'sha512';
        $options['algorithm'] = strtolower($options['algorithm']);

        if (!in_array($options['algorithm'], $algorithms))
            throw new \Exception($options['algorithm']." is not supported");

        $canonicalRepresentation = HmacUtils::createCanonicalRepresentation($req->getMethod(), $headersToSign, $req->getUrl());
        $signature = HmacUtils::computeSignature($canonicalRepresentation, $options['secret'], $options['algorithm']);
        //$logger->debug('Canonical Representation ', array($canonicalRepresentation, $signature)); 
        $req->setHeader('Authorization', $options['algorithm'].' '.$options['key'].' '.$signature);
    }
1163815
public function setLanguage(Event $event)
    {
        /**
         * @var $app Application
         */
        $app = $event->data;
        foreach ($this->handlers as $handler) {
            $intersection = array_intersect($this->languages, $handler->getLanguages());
            if (!empty($intersection)) {
                Yii::$app->language = current($intersection);
                break;
            }
        }
        $app->trigger(self::EVENT_AFTER_SETTING_LANGUAGE);
    }
438884
public function beforePrepare(Event $event)
	{
		$command = $event['command'];
		$operation = $command->getOperation();
		$client = $command->getClient();

		if ($command->getName() !== 'updateEntity') return;
		if ($operation->getParam('collection')->getDefault() !== 'user') return;

		// Attempt to get the model's deleted at value from the array of values passed
		// to the command.
		$statusValue = false;

		if ($command->offsetExists(Model::DELETED_AT))
		{
			$statusValue = $command->offsetGet(Model::DELETED_AT);
		}
		elseif ($command->offsetExists('_kmd'))
		{
			$_kmd = array_dot($command->offsetGet('_kmd'));

			$statusField = MODEL::DELETED_AT;
			$statusField = str_replace('_kmd.', '', MODEL::DELETED_AT);

			if (array_key_exists($statusField, $_kmd))
			{
				$statusValue = $_kmd[$statusField];
			}
		}

		// Could not determine the status field.
		if ($statusValue === false)
		{
			return;
		}
		// Suspend the user.
		elseif (!is_null($statusValue))
		{
			$event->stopPropagation();

			$suspendCommand = $client->getCommand('deleteEntity', array(
				'collection' => 'user',
				'_id' => $command->offsetGet('_id'),
			));
			$suspendCommand->execute();
		}
		// Restore.
		else
		{
			$event->stopPropagation();

			$restoreCommand = $client->getCommand('restore', array(
				'_id' => $command->offsetGet('_id'),
			));
			$restoreCommand->execute();
		}
	}
1185422
public function beforeRun(SourceSetEvent $sourceSetEvent): void
    {
        /** @var SourceInterface $source */
        foreach ($sourceSetEvent->updatedSources() as $source) {
            foreach ($this->extensions as $extension) {
                if (fnmatch("*.{$extension}", $source->filename())) {
                    $source->data()->append('converters', SculpinTextileBundle::CONVERTER_NAME);
                    break;
                }
            }
        }
    }
178508
public function afterCreate(PersistenceEvent $event) {
    if ($event->getAction() == PersistenceAction::CREATE) {
      $oldOid = $event->getOldOid();
      $oldOidStr = $oldOid != null ? $oldOid->__toString() : null;
      if ($oldOidStr != null && isset($this->createdTranslations[$oldOidStr])) {
        foreach ($this->createdTranslations[$oldOidStr] as $translation) {
          $translation->setValue('objectid', $event->getObject()->getOID()->__toString());
        }
      }
    }
  }
432244
public function handleLoadLanguageFile(LoadLanguageFileEvent $event)
    {
        /** @var System $systemAdapter */
        $systemAdapter = $this->framework->getAdapter(System::class);

        $systemAdapter->loadLanguageFile($event->getFileName(), $event->getLanguage(), $event->isCacheIgnored());
    }
854908
public function beforeFilter(\Cake\Event\Event $event)
    {
        parent::beforeFilter($event);

        // get the type-string
        $type = $this->PostTypes->postTypeFinder($this->request);
        $this->_type = $type;

        // check if the string exists. Will throw an exception
        $this->PostTypes->check($type, ['exception' => true]);

        // intialize the settings
        $this->Settings = $this->PostTypes->get($type);

        // lets initialize the model too
        $this->Model = $this->loadModel($this->Settings['model']);
    }
1289510
public function startFor(Domain\Event $event) : void
    {
        if (true === $this->started()) {
            throw new Exception\SubscriptionAlreadyStarted($this);
        }

        $this->applyEvent(new SubscriptionStarted($event, $this->clock->now()));
    }
529500
public function removeDraftChildren(RemoveDraftEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticleDocument) {
            return;
        }

        foreach ($document->getChildren() as $child) {
            if (LocalizationState::GHOST === $this->documentInspector->getLocalizationState($child)) {
                continue;
            }

            try {
                $this->documentManager->removeDraft($child, $event->getLocale());
            } catch (PathNotFoundException $exception) {
                // child is not available in live workspace
                $node = $this->documentInspector->getNode($child);
                $node->remove();
            }
        }
    }
516946
public function preDelete(DeleteEvent $event)
    {
        /** @var User $user */
        $user = $event->getObject();
        $userRole = $this->roleManager->getUserRole($user->getUsername());

        //soft delete~
        $user->setIsRemoved(true);
        $user->setEmail('email#'.$user->getId());
        $user->setFirstName('firstname#'.$user->getId());
        $user->setLastName('lastname#'.$user->getId());
        $user->setPlainPassword(uniqid());
        $user->setUsername('username#'.$user->getId());
        $user->setPublicUrl('removed#'.$user->getId());
        $user->setAdministrativeCode('code#'.$user->getId());
        $user->setIsEnabled(false);

        // keeping the user's workspace with its original code
        // would prevent creating a user with the same username
        // todo: workspace deletion should be an option
        $ws = $user->getPersonalWorkspace();

        if ($ws) {
            $ws->setCode($ws->getCode().'#deleted_user#'.$user->getId());
            $ws->setDisplayable(false);
            $this->om->persist($ws);
        }

        if ($userRole) {
            $this->om->remove($userRole);
        }
        $this->om->persist($user);
        $this->om->flush();

        //dispatch some events but they should be listening the same as we are imo.
        //something should be done for event listeners
        $this->dispatcher->dispatch('claroline_users_delete', 'GenericData', [[$user]]);
        $this->dispatcher->dispatch('log', 'Log\LogUserDelete', [$user]);
        $this->dispatcher->dispatch('delete_user', 'DeleteUser', [$user]);
    }
240035
public function beforeDelete($event)
    {
        $oldId = $this->owner->{$this->savedAttribute};
        if (($oldModel = FileModel::findOne($oldId)) !== null) {
            $event->isValid = $event->isValid && $oldModel->delete();
        }
    }
505578
public function preFlush(PreFlushEventArgs $event)
    {
        $entityManager = $event->getEntityManager();
        $uow = $entityManager->getUnitOfWork();

        foreach ($uow->getIdentityMap() as $class => $entities) {
            foreach ($entities as $entity) {
                if ($entity instanceof DeletableInterface) {
                    if ($entity->isDeleted()) {
                        $entityManager->remove($entity);
                    }
                }
            }
        }
    }