public function thumbnail($urn, $width = null, $height = null) { $encodedURN = base64_encode($urn); $config = lmv::config(); $endpoint = sprintf($config['getThumbnailsEndPoint'], $encodedURN); $query = []; if ($width !== null) { $query['width'] = $width; } if ($height !== null) { $query['height'] = $height; } Unirest\Request::verifyPeer(false); $response = Unirest\Request::get($endpoint, array('Authorization' => 'Bearer ' . lmv::bearer()), $query); if ($response->code != lmv::HTTP_OK) { utils::log('thumbnail fail ' . $response->code); return null; } return $response->raw_body; }
public function translate() { //utils::log ('translate launched!') ; try { $path = $this->lmv->dataDir("/{$this->identifier}.dependencies.json", true); if ($path === false) { throw new Exception('No dependency file found'); } $content = file_get_contents($path); $connections = json_decode($content); if ($content === false || !is_object($connections) || is_null($connections[0])) { utils::log('ERROR: project dependencies corrupted :('); // Rebuild one master only $connections = (object) array('uniqueIdentifier' => $this->identifier, 'children' => []); } $items = [$this->identifier]; $items = array_merge($items, $this->traverseConnections($connections->children)); // This is to help the upload progress bar to be more precise if (file_put_contents($path, json_encode($items)) === false) { utils::log('ERROR: project dependencies not saved :('); throw new Exception('ERROR: project dependencies not saved :('); } // Bucket $policy = 'transient'; $r1 = $this->lmv->createBucketIfNotExist($policy); if ($r1 == null) { // No need to continue if the bucket was not created utils::log('Failed to create bucket!'); throw new Exception('Failed to create bucket!'); } utils::log('Bucket created (or did exist already)!'); // Uploading file(s) utils::log('Uploading(s)'); foreach ($items as $item) { utils::log(" uploading {$item}"); $r2 = $this->lmv->uploadFile($item); if ($r2 == null) { utils::log(" Failed to upload {$item}"); throw new Exception("Failed to upload {$item}"); } utils::log("{$item} upload completed!"); } utils::log('All files uploaded'); // Dependencies $r3 = $this->lmv->setDependencies(count($items) == 1 ? null : $connections); if ($r3 == null) { utils::log('Failed to set connections'); throw new Exception('Failed to set connections'); } utils::log('References set, launching translation'); // Register $r4 = $this->lmv->register($connections); if ($r3 == null) { utils::log('URN registration for translation failed'); throw new Exception('URN registration for translation failed'); } utils::log('URN registered for translation'); // We are done for now! // Just remember locally we did submit the project for translation $urn = $this->lmv->getURN($this->identifier); $urn = base64_encode($urn); $data = (object) array('guid' => $urn, 'progress' => '0% complete', 'startedAt' => gmdate(DATE_RFC2822), 'status' => 'requested', 'success' => '0%', 'urn' => $urn); $path = $this->lmv->dataDir("/{$this->identifier}.resultdb.json"); if (file_put_contents($path, json_encode($data)) === false) { utils::log("Could not save file to disk - {$path}"); } $filesystem = new Filesystem(); foreach ($items as $item) { $filesystem->remove($this->lmv->dataDir("/{$item}.json")); } $filesystem->remove($this->lmv->dataDir("/{$this->identifier}.dependencies.json")); $filesystem->remove($this->lmv->dataDir("/{$this->identifier}.connections.json")); return true; } catch (Exception $ex) { //- We are done! email me if any error utils::log('Something wrong happened during upload'); $loader = new Twig_Loader_Filesystem(array($this->lmv->viewsDir('', true))); $environment = new Twig_Environment($loader, array('debug' => false, 'charset' => 'utf-8', 'strict_variables' => true)); $content = $environment->render('email-xlt-failed.twig', array('ID' => $this->identifier)); $config = lmv::config(); $mjet = new Mailjet($config['MAILJET1'], $config['MAILJET2']); $mjet->sendContent('ADN Sparks <*****@*****.**>', '*****@*****.**', 'Autodesk View & Data API Extractor app failed to translate a project', 'html', $content); $filesystem = new Filesystem(); $filesystem->rename($this->lmv->dataDir("/{$this->identifier}.resultdb.json", true), $this->lmv->dataDir("/{$this->identifier}.resultdb.failed"), true); return false; } }
protected function NotifyError() { $loader = new Twig_Loader_Filesystem(array($this->lmv->viewsDir('', true))); $environment = new Twig_Environment($loader, array('debug' => false, 'charset' => 'utf-8', 'strict_variables' => true)); $content = $environment->render('email-extract-failed.twig', array('ID' => $this->identifier)); $config = lmv::config(); $mjet = new Mailjet($config['MAILJET1'], $config['MAILJET2']); $mjet->sendContent('ADN Sparks <*****@*****.**>', $config['mailTo'], 'Autodesk View & Data API Extraction failed', 'html', $content); //'replyTo': '*****@*****.**', //'forceEmbeddedImages': true }