Пример #1
0
 /**
  * To rename a file from the importr you
  * have to use the "rename: 1" statement in
  * your configuration. The file will be
  * prefixed with the current (human readable)
  * timestamp.
  *
  * Caution: after this method, the file is moved
  * you should only use this in the before
  * configuration if you are fully aware of it!
  *
  * @param  ManagerInterface $manager
  * @param  Import           $import
  * @return void
  */
 public function execute(ManagerInterface $manager, Import $import)
 {
     $configuration = $import->getStrategy()->getConfiguration();
     if (isset($configuration['after']['rename'])) {
         $oldFileName = $this->fileService->getFileAbsFileName($import->getFilepath());
         $info = pathinfo($oldFileName);
         $newFileName = $info['dirname'] . DIRECTORY_SEPARATOR . date('YmdHis') . '_' . $info['basename'];
         rename($oldFileName, $newFileName);
     }
 }
Пример #2
0
 /**
  * @test
  */
 public function does_execute_rename_file_when_configured()
 {
     $manager = $this->getMock(ManagerInterface::class);
     $strategy = $this->getMock(Strategy::class);
     $strategy->expects($this->once())->method('getConfiguration')->will($this->returnValue(['after' => ['rename' => true]]));
     $import = $this->getMock(Import::class);
     $import->expects($this->once())->method('getStrategy')->will($this->returnValue($strategy));
     $file = vfsStream::newFile('import.csv')->at($this->root)->setContent("test;test");
     $oldFileName = $file->getName();
     $this->fileService->expects($this->any())->method('getFileAbsFileName')->will($this->returnCallback(function () use($file) {
         return $file->url();
     }));
     $this->fixture->execute($manager, $import);
     $children = $this->root->getChildren();
     $this->assertEquals(1, sizeof($children));
     $this->assertRegExp('/^[0-9]{14}_' . $oldFileName . '$/', $children[0]->getName());
 }