You are here

public function CmisBrowser::getDocument in CMIS API 8.2

Same name and namespace in other branches
  1. 8 src/CmisBrowser.php \Drupal\cmis\CmisBrowser::getDocument()
  2. 3.0.x src/CmisBrowser.php \Drupal\cmis\CmisBrowser::getDocument()

Get document by id.

Parameters

string $config: Entity label.

string $document_id: CMIS document id.

1 string reference to 'CmisBrowser::getDocument'
cmis.routing.yml in ./cmis.routing.yml
cmis.routing.yml

File

src/CmisBrowser.php, line 134

Class

CmisBrowser
Description of CmisBrowser.

Namespace

Drupal\cmis

Code

public function getDocument($config = '', $document_id = '') {
  \Drupal::service('cmis.connection_api')
    ->checkConnectionIsAlive($config);
  $this
    ->init($config, $document_id, 'cmis:document');
  if ($this->connection && !empty($this->current) && $this->current
    ->getBaseTypeId()
    ->__toString() == 'cmis:document') {
    $id = $this->current
      ->getId();
    $content = '';
    try {
      $content = $this->current
        ->getContentStream($id);
    } catch (CMISException $e) {

      // TODO: testing this.
      $headers = [
        '' => 'HTTP/1.1 503 Service unavailable',
      ];
      $response = new Response($content, 503, $headers);
      $response
        ->send();
      exit;
    }
    $mime = $this->current
      ->getContentStreamMimeType();
    $headers = [
      'Cache-Control' => 'no-cache, must-revalidate',
      'Content-type' => $mime,
      'Content-Disposition' => 'attachment; filename="' . $this->current
        ->getName() . '"',
    ];
    $response = new Response($content, 200, $headers);
    $response
      ->send();

    // TODO: Why a print and an exit?
    print $content;
    exit;
  }
}