Example #1
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $config = ArrayLoader::load(config('tradukoj'));
     $this->debugStatus = $this->option('debug');
     $output = $this->getOutput();
     $clientSocketApi = new ClientSocketApi($config, new Socket(), new PostCurl(), new ConsoleOutput(), $this->debugStatus);
     $this->info("Connecting with Tradukoj ...");
     $clientSocketApi->init();
     if ($this->option('upload-first')) {
         $catalogs = $this->manager->getCatalogs();
         foreach ($catalogs as $catalog) {
             $output->writeln(PHP_EOL . sprintf('<info>Uploading catalog %s ...</info>', $catalog));
             $data = $this->manager->getTranslations($catalog);
             $this->output->writeln('uploadKeys("' . $catalog . '", $data)');
             $clientSocketApi->uploadKeys($catalog, $data);
         }
         $this->info('Done!');
         $clientSocketApi->shutdown();
         return;
     }
     // normal synchronization (not upload-first)
     $catalogs = $clientSocketApi->getCatalogIndex();
     foreach ($catalogs as $catalog) {
         $output->writeln(PHP_EOL . sprintf('Downloading catalog "%s" ...', $catalog));
         $translations = $clientSocketApi->downloadKeys($catalog);
         var_dump($translations);
         //$data = $this->manager->getTranslations($catalog);
         //$this->output->writeln('uploadKeys("' . $catalog . '", $data)');
         //$clientSocketApi->uploadKeys($catalog, $data);
     }
     $clientSocketApi->shutdown();
     $this->info('Done!');
 }
 public function testServiceCalls()
 {
     //        $debug = self::getProperty('debug');
     //        $debug->setValue($this->clientSocketApi, true);
     //
     //        $consoleOutput = new ConsoleOutput();
     //        $output = self::getProperty('output');
     //        $output->setValue($this->clientSocketApi, $consoleOutput);
     $init = $this->getProperty('init');
     $init->setValue($this->clientSocketApi, true);
     $result = $this->clientSocketApi->getBundleIndex();
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->getCatalogIndex();
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->getKeyIndex("messages");
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->getMessages("messages", "test.key");
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->getMessage("messages", "test.key", "en");
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->getComment("messages", "test.key");
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->putMessage("messages", "test.key", "en", "test");
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->updateMessageIfNewest("messages", "test.key", "en", "test", new \DateTime());
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->updateCommentIfNewest("messages", "test.key", "test", new \DateTime());
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->uploadKeys("messages", array());
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->downloadKeys("messages");
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->transDocIndex();
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->transDocSync("messages", "test.key", "en", "file", "document", new \DateTime());
     $this->assertFalse($result['result']);
     $result = $this->clientSocketApi->register();
     $this->assertFalse($result['result']);
     $shutdown = $this->getMethod('shutdown');
     $result = $shutdown->invoke($this->clientSocketApi);
     $this->assertFalse($result['result']);
     // the shutdown method switches init to false
     $init = $this->getProperty('init');
     $this->assertFalse($init->getValue($this->clientSocketApi));
 }