public function loadData($pid, $name, $tmpDir)
 {
     // Upload to WebDav
     $webDav = new WebDav($this->gdClient->getUsername(), $this->gdClient->getPassword(), $this->gdClient->getUserUploadUrl());
     $dimensionName = Identifiers::getIdentifier($name);
     $tmpFolderNameDimension = "{$pid}-{$dimensionName}-" . uniqid();
     $tmpFolderDimension = $tmpDir . '/' . Identifiers::getIdentifier($name);
     mkdir($tmpFolderDimension);
     $timeDimensionManifest = self::getDataLoadManifest($dimensionName);
     file_put_contents("{$tmpFolderDimension}/upload_info.json", $timeDimensionManifest);
     copy(__DIR__ . '/time-dimension.csv', "{$tmpFolderDimension}/{$dimensionName}.csv");
     $webDav->createFolder($tmpFolderNameDimension);
     $webDav->upload("{$tmpFolderDimension}/upload_info.json", $tmpFolderNameDimension);
     $webDav->upload("{$tmpFolderDimension}/{$dimensionName}.csv", $tmpFolderNameDimension);
     // Run ETL task of time dimensions
     try {
         $this->gdClient->getDatasets()->loadData($pid, $tmpFolderNameDimension);
     } catch (Exception $e) {
         $debugFile = "{$tmpFolderDimension}/{$pid}-etl.log";
         $logSaved = $webDav->saveLogs($tmpFolderDimension, $debugFile);
         if ($logSaved) {
             $data = file_get_contents($debugFile);
             if ($data) {
                 $data = json_decode($data, true);
                 if ($data) {
                     $e = new Exception(json_decode(file_get_contents($debugFile), true), $e->getCode(), $e);
                 }
             }
         }
         throw $e;
     }
 }
Example #2
0
 /**
  * Tests the `Client` constructor.
  */
 public function testConstructor()
 {
     $client = new Client(['username' => 'anonymous', 'password' => 'secret']);
     $this->assertEquals('secret', $client->getPassword());
     $this->assertEquals('anonymous', $client->getUsername());
     $this->assertSame($client, $client->setPassword(''));
     $this->assertEmpty($client->getPassword());
 }