public function progress(Silex\Application $app, $identifier)
 {
     $bucket = lmv::getDefaultBucket();
     $lmv = new lmv($bucket);
     $urn = $lmv->getURN($identifier);
     if ($urn == '') {
         // Ok, we might be uploading to oss - we will try to return a file upload progress
         $path = $app->dataDir("/{$identifier}.json", true);
         if ($path === false) {
             // No luck, let's return a default answer
             return new JsonResponse((object) array('guid' => '', 'progress' => 'uploading to oss', 'startedAt' => gmdate(DATE_RFC2822), 'status' => 'requested', 'success' => '0%', 'urn' => ''), Response::HTTP_OK);
         }
         $content = file_get_contents($path);
         $data = json_decode($content);
         $connections = null;
         try {
             $path = $app->dataDir("/{$identifier}.dependencies.json", true);
             $content = file_get_contents($path);
             $connections = json_decode($content);
             $size = 0;
             $uploaded = 0;
             foreach ($connections as $item) {
                 $path = $app->dataDir("/{$item}.json", true);
                 if ($path === false) {
                     utils::log("Something wrong happened during upload - {$item}");
                     continue;
                 }
                 $content = file_get_contents($path);
                 $data2 = json_decode($content);
                 $size += isset($data2->size) ? intval($data2->size) : $data2->objects[0]->size;
                 $uploaded += isset($data2->bytesPosted) ? intval($data2->bytesPosted) : $data2->objects[0]->size;
             }
             $pct = 0;
             if ($size != 0) {
                 $pct = intval(floor(100 * $uploaded / $size));
             }
             return new JsonResponse((object) array('guid' => '', 'progress' => 'uploading to oss', 'startedAt' => gmdate(DATE_RFC2822), 'status' => 'requested', 'success' => "{$pct}%", 'urn' => ''), Response::HTTP_OK);
         } catch (Exception $ex) {
             $connections = null;
             $pct = 0;
             if ($data->size != 0) {
                 $pct = intval(floor(100 * $data->bytesPosted / $data->size));
             }
             return new JsonResponse((object) array('guid' => '', 'progress' => 'uploading to oss', 'startedAt' => gmdate(DATE_RFC2822), 'status' => 'requested', 'success' => "{$pct}%", 'urn' => ''), Response::HTTP_OK);
         }
         return;
     }
     $response = $lmv->status($urn);
     if ($response === null) {
         return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']);
     }
     if ($response->progress == 'complete') {
         $path = $app->dataDir("/{$identifier}.resultdb.json");
         file_put_contents($path, json_encode($response));
     }
     return new JsonResponse($response, Response::HTTP_OK);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $identifier = $input->getArgument('identifier');
     if (!$identifier) {
         $identifier = '1799-Auobj';
     }
     $keys = $input->getOption('keys');
     foreach ($keys as $envkey) {
         putenv($envkey);
     }
     $bucket = lmv::getDefaultBucket();
     $lmv = new lmv($bucket);
     $urn = $lmv->getURN($identifier);
     //$path =utils::normalize (__DIR__ . '/../data/' . $identifier . '.lock') ;
     //file_put_contents ($path, json_encode ([ '*****@*****.**' ])) ;
     $extractor = new Extractor($identifier, $bucket);
     $bSuccess = $extractor->extract();
     utils::log($bSuccess ? 'ok' : 'oops');
 }
 public function project(Silex\Application $app, Request $request, $identifier)
 {
     $bucket = lmv::getDefaultBucket();
     $lmv = new lmv($bucket);
     $urn = $lmv->getURN($identifier);
     if ($urn == '') {
         return new Response('', Response::HTTP_NOT_FOUND, ['Content-Type' => 'text/plain']);
     }
     $path = $app->extractDir("/{$identifier}.zip", true);
     if ($path) {
         return new Response('', Response::HTTP_OK, ['Content-Type' => 'text/plain']);
     }
     $lock = $app->dataDir("/{$identifier}.lock");
     $email = $request->query->get('email');
     if (realpath($lock)) {
         if (!empty($email)) {
             $data = json_decode(file_get_contents($lock));
             $data->emails[] = $email;
             if (file_put_contents($lock, json_encode($data)) === false) {
                 utils::log("Could not create lock file - {$lock}");
             }
         }
         return new Response('', Response::HTTP_OK, ['Content-Type' => 'text/plain']);
     } else {
         $list = !empty($email) ? [$email] : [];
         $data = (object) array('progress' => 0, 'emails' => $list);
         if (file_put_contents($lock, json_encode($data)) === false) {
             utils::log("Could not create lock file - {$lock}");
         }
     }
     $result = utils::executeScript("/extract.php lmv:extractor {$identifier}", true);
     if ($result === false) {
         return new Response('', Response::HTTP_INTERNAL_SERVER_ERROR, ['Content-Type' => 'text/plain']);
     }
     return new Response('ok', Response::HTTP_OK, ['Content-Type' => 'text/plain']);
 }