Exemple #1
0
 /**
  * Do the save for a POSTed record.
  *
  * @param array   $formValues
  * @param array   $contenttype  The contenttype data
  * @param integer $id           The record ID
  * @param boolean $new          If TRUE this is a new record
  * @param string  $returnTo
  * @param string  $editReferrer
  *
  * @return Response
  */
 public function action(array $formValues, array $contenttype, $id, $new, $returnTo, $editReferrer)
 {
     $contentTypeSlug = $contenttype['slug'];
     $repo = $this->em->getRepository($contentTypeSlug);
     // If we have an ID now, this is an existing record
     if ($id) {
         $content = $repo->find($id);
         $oldContent = clone $content;
         $oldStatus = $content['status'];
     } else {
         $content = $repo->create(['contenttype' => $contentTypeSlug, 'status' => $contenttype['default_status']]);
         $oldContent = null;
         $oldStatus = 'draft';
     }
     // Don't allow spoofing the ID.
     if ($content->getId() !== null && (int) $id !== $content->getId()) {
         if ($returnTo === 'ajax') {
             throw new AccessControlException("Don't try to spoof the id!");
         }
         $this->loggerFlash->error("Don't try to spoof the id!");
         return new RedirectResponse($this->generateUrl('dashboard'));
     }
     $this->setPostedValues($content, $formValues, $contenttype);
     $this->setTransitionStatus($content, $contentTypeSlug, $id, $oldStatus);
     // Get the associated record change comment
     $comment = isset($formValues['changelog-comment']) ? $formValues['changelog-comment'] : '';
     // Save the record
     return $this->saveContentRecord($content, $oldContent, $contenttype, $new, $comment, $returnTo, $editReferrer);
 }
Exemple #2
0
 /**
  * Run the create/alter query.
  *
  * @param string $tableName
  * @param string $query
  *
  * @return \Doctrine\DBAL\Driver\Statement|null
  */
 protected function runQuery($tableName, $query)
 {
     try {
         return $this->connection->query($query);
     } catch (DBALException $e) {
         $this->loggerSystem->critical($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
         $this->loggerFlash->error(Trans::__('An error occured while updating `%TABLE%`. The error is %ERROR%', ['%TABLE%' => $tableName, '%ERROR%' => $e->getMessage()]));
     }
 }
 /**
  * Trigger database schema checks if required.
  *
  * @param GetResponseEvent $event
  */
 protected function schemaCheck(GetResponseEvent $event)
 {
     $session = $event->getRequest()->getSession();
     $validSession = $session->isStarted() && $session->get('authentication');
     $expired = $this->schemaManager->isCheckRequired();
     if ($validSession && $expired && $this->schemaManager->isUpdateRequired()) {
         $msg = Trans::__("The database needs to be updated/repaired. Go to 'Configuration' > '<a href=\"%link%\">Check Database</a>' to do this now.", ['%link%' => $this->urlGenerator->generate('dbcheck')]);
         $this->loggerFlash->error($msg);
     }
 }
Exemple #4
0
 /**
  * Transition a record's owner if permitted.
  *
  * @param Content $entity
  * @param integer $ownerId
  */
 protected function transistionRecordOwner(Content $entity, $ownerId)
 {
     $recordId = $entity->getId();
     $contentTypeName = (string) $entity->getContenttype();
     $canChangeOwner = $this->users->isAllowed("contenttype:{$contentTypeName}:change-ownership:{$recordId}");
     if (!$canChangeOwner) {
         $this->loggerFlash->error(Trans::__('general.access-denied.content-not-modified', ['%title%' => $entity->getTitle()]));
         return;
     }
     $entity->setOwnerid($ownerId);
     $entity->_modified = true;
 }
 /**
  * Trigger database schema checks if required.
  *
  * @param GetResponseEvent $event
  */
 protected function schemaCheck(GetResponseEvent $event)
 {
     $session = $event->getRequest()->getSession();
     $validSession = $session->isStarted() && $session->get('authentication');
     $expired = $this->schemaManager->isCheckRequired();
     // Don't show the check if we're in the dbcheck already.
     $notInCheck = !in_array($event->getRequest()->get('_route'), ['dbcheck', 'dbupdate_result', 'dbupdate']);
     if ($validSession && $expired && $this->schemaManager->isUpdateRequired() && $notInCheck) {
         $msg = Trans::__("The database needs to be updated/repaired. Go to 'Configuration' > '<a href=\"%link%\">Check Database</a>' to do this now.", ['%link%' => $this->urlGenerator->generate('dbcheck')]);
         $this->loggerFlash->error($msg);
     }
 }
Exemple #6
0
 /**
  * Load a single extension.
  *
  * @param PackageDescriptor $descriptor
  */
 private function addManagedExtension(PackageDescriptor $descriptor)
 {
     $className = $descriptor->getClass();
     if ($this->isClassLoadable($className) === false) {
         $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         return;
     }
     /** @var ExtensionInterface $extension */
     $extension = new $className();
     if ($extension instanceof ExtensionInterface) {
         $baseDir = $this->extFs->getDir($descriptor->getPath());
         $webDir = $this->webFs->getDir($descriptor->getWebPath());
         $this->add($extension, $baseDir, $webDir, $descriptor->getName())->setDescriptor($descriptor);
     } else {
         $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
     }
 }
Exemple #7
0
 /**
  * Load a single extension.
  *
  * @param PackageDescriptor $descriptor
  */
 private function addManagedExtension(PackageDescriptor $descriptor)
 {
     $className = $descriptor->getClass();
     if ($this->isClassLoadable($className) === false) {
         if ($descriptor->getType() === 'local' && $this->isClassLoadable('Wikimedia\\Composer\\MergePlugin') === false) {
             $this->flashLogger->error(Trans::__('general.phrase.error-local-extension-set-up-incomplete', ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         } else {
             $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         }
         return;
     }
     /** @var ExtensionInterface $extension */
     $extension = new $className();
     if ($extension instanceof ExtensionInterface) {
         $baseDir = $this->extFs->getDir($descriptor->getPath());
         $webDir = $this->webFs->getDir($descriptor->getWebPath());
         $this->add($extension, $baseDir, $webDir, $descriptor->getName())->setDescriptor($descriptor);
     } else {
         $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
     }
 }
Exemple #8
0
 /**
  * Load a single extension.
  *
  * @param PackageDescriptor $descriptor
  */
 private function addManagedExtension(PackageDescriptor $descriptor)
 {
     $className = $descriptor->getClass();
     if (class_exists($className) === false) {
         if ($descriptor->getType() === 'local' && class_exists('Wikimedia\\Composer\\MergePlugin') === false) {
             $this->flashLogger->error(Trans::__("Local extension set up incomplete. Please run 'Install all packages' on the Extensions page.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         } else {
             $this->flashLogger->error(Trans::__("Extension package %NAME% has an invalid class '%CLASS%' and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
         }
         return;
     }
     /** @var ExtensionInterface $extension */
     $extension = new $className();
     if ($extension instanceof ExtensionInterface) {
         $baseDir = $this->filesystem->getDir($descriptor->getPath());
         $relativeUrl = sprintf('/extensions/%s/web/', $descriptor->getPath());
         $this->add($extension, $baseDir, $relativeUrl, $descriptor->getName())->setDescriptor($descriptor);
     } else {
         $this->flashLogger->error(Trans::__("Extension package %NAME% base class '%CLASS%' does not implement \\Bolt\\Extension\\ExtensionInterface and has been skipped.", ['%NAME%' => $descriptor->getName(), '%CLASS%' => $className]));
     }
 }