Пример #1
0
 /**
  * Handle the PHP shutdown event.
  *
  * @return void
  */
 public function handleShutdown()
 {
     if (!is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
         $e = new ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']);
         $this->emitter->run('application.error', $e);
     }
 }
Пример #2
0
 /**
  * Creates a new file for Directus Media
  *
  * @param string $filePath
  * @param string $targetName
  *
  * @return Array file info
  */
 private function processUpload($filePath, $targetName)
 {
     // set true as $filePath it's outside adapter path
     // $filePath is on a temporary php directory
     $fileData = $this->getFileInfo($filePath, true);
     $mediaPath = $this->filesystem->getPath();
     $fileData['title'] = Formatting::fileNameToFileTitle($targetName);
     $targetName = $this->getFileName($targetName);
     $finalPath = rtrim($mediaPath, '/') . '/' . $targetName;
     $data = file_get_contents($filePath);
     $this->emitter->run('files.saving', ['name' => $targetName, 'size' => strlen($data)]);
     $this->filesystem->getAdapter()->write($targetName, $data);
     $this->emitter->run('files.saving:after', ['name' => $targetName, 'size' => strlen($data)]);
     $fileData['name'] = basename($finalPath);
     $fileData['date_uploaded'] = DateUtils::now();
     $fileData['storage_adapter'] = $this->config['adapter'];
     return $fileData;
 }
 /**
  * @param Delete $delete
  * @return mixed
  * @throws Exception\RuntimeException
  * @throws \Directus\Acl\Exception\UnauthorizedTableBigDeleteException
  * @throws \Directus\Acl\Exception\UnauthorizedTableDeleteException
  */
 protected function executeDelete(Delete $delete)
 {
     $cuurrentUserId = null;
     if (Auth::loggedIn()) {
         $currentUser = Auth::getUserInfo();
         $currentUserId = intval($currentUser['id']);
     }
     $deleteState = $delete->getRawState();
     $deleteTable = $this->getRawTableNameFromQueryStateTable($deleteState['table']);
     $cmsOwnerColumn = $this->acl->getCmsOwnerColumnByTable($deleteTable);
     $canBigDelete = $this->acl->hasTablePrivilege($deleteTable, 'bigdelete');
     $canDelete = $this->acl->hasTablePrivilege($deleteTable, 'delete');
     $aclErrorPrefix = $this->acl->getErrorMessagePrefix();
     if (!TableSchema::hasTableColumn($deleteTable, STATUS_COLUMN_NAME)) {
         if ($this->acl->hasTablePrivilege($deleteTable, 'bigdelete')) {
             $canBigDelete = true;
         } else {
             if ($this->acl->hasTablePrivilege($deleteTable, 'delete')) {
                 $canDelete = true;
             }
         }
     }
     // @todo: clean way
     if ($deleteTable === 'directus_bookmarks') {
         $canBigDelete = true;
     }
     /**
      * ACL Enforcement
      */
     if (!$canBigDelete && !$canDelete) {
         throw new UnauthorizedTableBigDeleteException($aclErrorPrefix . ' forbidden to hard delete on table `' . $deleteTable . '` because it has Status Column.');
     }
     if (false === $cmsOwnerColumn) {
         // cannot delete if there's no magic owner column and can't big delete
         if (!$canBigDelete) {
             // All deletes are "big" deletes if there is no magic owner column.
             throw new UnauthorizedTableBigDeleteException($aclErrorPrefix . 'The table `' . $deleteTable . '` is missing the `user_create_column` within `directus_tables` (BigHardDelete Permission Forbidden)');
         }
     } else {
         if (!$canBigDelete) {
             // Who are the owners of these rows?
             list($predicateResultQty, $predicateOwnerIds) = $this->acl->getCmsOwnerIdsByTableGatewayAndPredicate($this, $deleteState['where']);
             if (!in_array($currentUserId, $predicateOwnerIds)) {
                 //   $exceptionMessage = "Table harddelete access forbidden on $predicateResultQty `$deleteTable` table records owned by the authenticated CMS user (#$currentUserId).";
                 $groupsTableGateway = self::makeTableGatewayFromTableName($this->acl, 'directus_groups', $this->adapter);
                 $group = $groupsTableGateway->find($this->acl->getGroupId());
                 $exceptionMessage = '[' . $group['name'] . '] permissions only allow you to [delete] your own items.';
                 //   $aclErrorPrefix = $this->acl->getErrorMessagePrefix();
                 throw new UnauthorizedTableDeleteException($exceptionMessage);
             }
         }
     }
     try {
         $this->emitter->run('table.delete:before', [$deleteTable]);
         $this->emitter->run('table.delete.' . $deleteTable . ':before');
         $result = parent::executeDelete($delete);
         $this->emitter->run('table.delete', [$deleteTable]);
         $this->emitter->run('table.delete:after', [$deleteTable]);
         $this->emitter->run('table.delete.' . $deleteTable);
         $this->emitter->run('table.delete.' . $deleteTable . ':after');
         return $result;
     } catch (\Zend\Db\Adapter\Exception\InvalidQueryException $e) {
         if ('production' !== DIRECTUS_ENV) {
             throw new \RuntimeException('This query failed: ' . $this->dumpSql($delete), 0, $e);
         }
         // @todo send developer warning
         throw $e;
     }
 }