public function testAllRecordsStash() { $record1 = new Record($this->connection->getCurrentContentTypeDefinition(), 'New Record'); $record1->setID(1); $record2 = new Record($this->connection->getCurrentContentTypeDefinition(), 'New Record'); $record2->setID(2); $allRecords = [$record1, $record2]; $dataDimensions = $this->connection->getCurrentDataDimensions(); $result = $this->invokeMethod($this->connection, 'hasStashedAllRecords', ['profiles', $dataDimensions]); $this->assertFalse($result); $this->invokeMethod($this->connection, 'stashRecord', [$record1, $dataDimensions]); $result = $this->invokeMethod($this->connection, 'hasStashedAllRecords', ['profiles', $dataDimensions]); $this->assertFalse($result); $this->invokeMethod($this->connection, 'stashAllRecords', [$allRecords, $dataDimensions]); $result = $this->invokeMethod($this->connection, 'hasStashedAllRecords', ['profiles', $dataDimensions]); $this->assertTrue($result); $result = $this->invokeMethod($this->connection, 'getStashedAllRecords', ['profiles', $dataDimensions]); $this->assertCount(2, $result); $this->invokeMethod($this->connection, 'unStashRecord', ['profiles', 1, $dataDimensions]); $result = $this->invokeMethod($this->connection, 'getStashedAllRecords', ['profiles', $dataDimensions]); $this->assertCount(1, $result); $this->invokeMethod($this->connection, 'unStashAllRecords', ['profiles', $dataDimensions]); $result = $this->invokeMethod($this->connection, 'hasStashedAllRecords', ['profiles', $dataDimensions]); $this->assertFalse($result); $result = $this->invokeMethod($this->connection, 'getStashedAllRecords', ['profiles', $dataDimensions]); $this->assertFalse($result); }
public function importXLSX(Repository $repository, $contentTypeName, $filename, $workspace = 'default', $language = 'default', $viewName = 'exchange') { $this->count = 0; $this->records = null; $this->stash = array(); $this->error = false; $repository->selectContentType($contentTypeName); // Select view and fallback if necessary $contentTypeDefinition = $repository->getContentTypeDefinition(); $viewDefinition = $contentTypeDefinition->getExchangeViewDefinition($viewName); $viewName = $viewDefinition->getName(); $repository->selectWorkspace($workspace); $repository->selectLanguage($language); $repository->selectView($viewName); $objPHPExcel = \PHPExcel_IOFactory::load($filename); if ($objPHPExcel) { if ($this->isTruncateRecords()) { $this->deleteEffectiveRecords($repository, $workspace, $viewName, $language); } $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); // e.g. 10 $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F' $highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5 $idColumnIndex = null; $propertiesColumnIndices = array(); for ($i = 0; $i <= $highestColumnIndex; $i++) { $value = trim($objWorksheet->getCellByColumnAndRow($i, 1)->getValue()); if ($value != '') { if (substr($value, 0, 1) == '.') { if ($value == '.id') { $idColumnIndex = $i; } } else { $value = Util::generateValidIdentifier($value); if ($contentTypeDefinition->hasProperty($value, $viewName)) { $this->writeln('Detected valid property ' . $value); $propertiesColumnIndices[$value] = $i; } } } } $this->writeln(''); if (count($propertiesColumnIndices) != 0) { for ($row = 2; $row <= $highestRow; ++$row) { $id = null; if ($idColumnIndex !== null) { if (!$this->isGenerateNewIDs()) { $id = $objWorksheet->getCellByColumnAndRow($idColumnIndex, $row)->getValue(); } } $properties = array(); foreach ($propertiesColumnIndices as $property => $col) { $value = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); $properties[$property] = $value; } $record = new Record($contentTypeDefinition, 'Imported Record', $viewName, $workspace, $language); $record->setProperties($properties); $record->setID($id); $msg = $this->stashRecord($repository, $record, $workspace, $viewName, $language); $this->writeln($msg); } $this->writeln(''); $this->writeln('Found ' . $this->count . ' records to import'); $this->writeln(''); if ($this->count != 0) { $this->writeln('Starting bulk import'); $this->writeln(''); $this->saveRecords($repository); $this->writeln(''); $this->writeln(''); } } else { $this->writeln('Excel does not contain matching property columns.'); } } else { $this->writeln('Error parsing Excel file.'); $this->error = true; } return !$this->error; }