/** * Extract the zip archive to be imported * * @throws \RuntimeException When archive cannot be opened or extracted * or does not contain exactly one csv file */ protected function extractZipArchive() { $archive = new \ZipArchive(); $status = $archive->open($this->filePath); if (true !== $status) { throw new \RuntimeException(sprintf('Error "%d" occurred while opening the zip archive.', $status)); } else { $targetDir = sprintf('%s/%s_%d_%s', pathinfo($this->filePath, PATHINFO_DIRNAME), pathinfo($this->filePath, PATHINFO_FILENAME), $this->stepExecution->getId(), md5(microtime() . $this->stepExecution->getId())); if ($archive->extractTo($targetDir) !== true) { throw new \RuntimeException('Error occurred while extracting the zip archive.'); } $archive->close(); $this->extractedPath = $targetDir; $csvFiles = glob($targetDir . '/*.[cC][sS][vV]'); $csvCount = count($csvFiles); if (1 !== $csvCount) { throw new \RuntimeException(sprintf('Expecting the root directory of the archive to contain exactly 1 csv file, found %d', $csvCount)); } $this->filePath = current($csvFiles); } }
/** * {@inheritDoc} */ public function getId() { if ($this->__isInitialized__ === false) { return (int) parent::getId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); }
public function testGetId() { $this->assertNull($this->stepExecution->getId()); }