Skip to content

Commit

Permalink
Merge branch '1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed Dec 3, 2018
2 parents 9f94ef6 + ee587fe commit ba13194
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 19 deletions.
22 changes: 16 additions & 6 deletions bundle/Command/ConvertXmlTextToRichTextCommand.php
Expand Up @@ -511,7 +511,9 @@ protected function waitForChild(OutputInterface $output)
$output->write($process->getIncrementalOutput());
$output->write($process->getIncrementalErrorOutput());
}
sleep(1);
if (!$childEnded) {
sleep(1);
}
}

return;
Expand Down Expand Up @@ -615,8 +617,11 @@ protected function dumpOnErrors($errors, $dataText, $contentobjectId, $contentob

protected function convertFields($dryRun, $contentId, $checkDuplicateIds, $checkIdValues, $offset, $limit)
{
$statement = $this->gateway->getFieldRows('ezxmltext', $contentId, $offset, $limit);
$statement = $this->gateway->getFieldRows(['ezxmltext', 'ezrichtext'], $contentId, $offset, $limit);
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
if ($row['data_type_string'] === 'ezrichtext') {
continue;
}
if (empty($row['data_text'])) {
$inputValue = Value::EMPTY_VALUE;
} else {
Expand Down Expand Up @@ -653,6 +658,7 @@ protected function progressBarStart(OutputInterface $output, $count)
{
if ($this->hasProgressBar) {
$this->progressBar = new ProgressBar($output, $count);
$this->progressBar->setFormat('very_verbose');
$this->progressBar->start();
}
}
Expand All @@ -673,8 +679,12 @@ protected function progressBarFinish()

protected function processFields($dryRun, $checkDuplicateIds, $checkIdValues, OutputInterface $output)
{
$count = $this->gateway->getRowCountOfContentObjectAttributes('ezxmltext', null);
$output->writeln("Found $count field rows to convert.");
$output->write('Finding total number of ezxmltext attributes to convert...');
$ezxmltextCount = $this->gateway->getRowCountOfContentObjectAttributes('ezxmltext', null);
$output->writeln(" Found $ezxmltextCount");
$output->write('Finding total number of ezxmltext and ezrichtext attributes...');
$count = $this->gateway->getRowCountOfContentObjectAttributes(['ezxmltext', 'ezrichtext'], null);
$output->writeln(" Found $count");

if ($count < self::MAX_OBJECTS_PER_CHILD * $this->maxConcurrency && $this->maxConcurrency > 1) {
$objectsPerChild = (int) ceil($count / $this->maxConcurrency);
Expand All @@ -699,14 +709,14 @@ protected function processFields($dryRun, $checkDuplicateIds, $checkIdValues, Ou
$this->convertFields($dryRun, null, $checkDuplicateIds, $checkIdValues, $offset, $limit);
}
$offset += $objectsPerChild;
} while ($offset + $objectsPerChild <= $count);
} while ($offset <= $count);

while (count($this->processes) > 0) {
$this->waitForChild($output);
$this->progressBarAdvance($objectsPerChild);
}
$this->progressBarFinish();
$output->writeln(PHP_EOL . 'Converted $count ezxmltext fields to richtext');
$output->writeln(PHP_EOL . "Converted $count ezxmltext fields to richtext");
}

protected function createDocument($xmlString)
Expand Down
37 changes: 24 additions & 13 deletions lib/FieldType/XmlText/Persistence/Legacy/ContentModelGateway.php
Expand Up @@ -92,18 +92,26 @@ public function getContentTypeFieldTypeUpdateQuery($fromFieldTypeIdentifier, $to
return $updateQuery;
}

public function getRowCountOfContentObjectAttributes($datatypeString, $contentId)
/**
* @param string|array $datatypes One datatype may be provided as string. Multiple datatypes areaccepted as array
* @param int $contentId
* @return int
*/
public function getRowCountOfContentObjectAttributes($datatypes, $contentId)
{
if (!is_array($datatypes)) {
$datatypes = [$datatypes];
}

$query = $this->dbal->createQueryBuilder();
$query->select('count(a.id)')
->from('ezcontentobject_attribute', 'a')
->where(
$query->expr()->eq(
$query->expr()->in(
'a.data_type_string',
':datatypestring'
$query->createNamedParameter($datatypes, Connection::PARAM_STR_ARRAY)
)
)
->setParameter(':datatypestring', $datatypeString);
);

if ($contentId !== null) {
$query->andWhere(
Expand All @@ -112,7 +120,7 @@ public function getRowCountOfContentObjectAttributes($datatypeString, $contentId
':contentid'
)
)
->setParameter(':contentid', $contentId);
->setParameter(':contentid', $contentId);
}

$statement = $query->execute();
Expand All @@ -124,25 +132,28 @@ public function getRowCountOfContentObjectAttributes($datatypeString, $contentId
* Get the specified field rows.
* Note that if $contentId !== null, then $offset and $limit will be ignored.
*
* @param string $datatypeString
* @param string|array $datatypes One datatype may be provided as string. Multiple datatypes are accepted as array
* @param int $contentId
* @param int $offset
* @param int $limit
* @return \Doctrine\DBAL\Driver\Statement|int
*/
public function getFieldRows($datatypeString, $contentId, $offset, $limit)
public function getFieldRows($datatypes, $contentId, $offset, $limit)
{
if (!is_array($datatypes)) {
$datatypes = [$datatypes];
}

$query = $this->dbal->createQueryBuilder();
$query->select('a.*')
->from('ezcontentobject_attribute', 'a')
->where(
$query->expr()->eq(
$query->expr()->in(
'a.data_type_string',
':datatypestring'
$query->createNamedParameter($datatypes, Connection::PARAM_STR_ARRAY)
)
)
->orderBy('a.id')
->setParameter(':datatypestring', $datatypeString);
->orderBy('a.id');

if ($contentId === null) {
$query->setFirstResult($offset)
Expand All @@ -154,7 +165,7 @@ public function getFieldRows($datatypeString, $contentId, $offset, $limit)
':contentid'
)
)
->setParameter(':contentid', $contentId);
->setParameter(':contentid', $contentId);
}

return $query->execute();
Expand Down
128 changes: 128 additions & 0 deletions tests/lib/FieldType/Persistence/Legacy/ContentModelGatewayTest.php
Expand Up @@ -97,6 +97,21 @@ public function getRowCountOfContentObjectAttributesProvider()
69,
3,
],
[
'ezxmltext',
null,
5,
],
[
'ezrichtext',
null,
2,
],
[
['ezxmltext', 'ezrichtext'],
null,
7,
],
];
}

Expand Down Expand Up @@ -241,6 +256,119 @@ public function getFieldRowsProvider()
],
],
],
[ // test multiple datatype strings
['ezxmltext', 'ezrichtext'],
null,
0,
100,
[
[
'attribute_original_id' => '0',
'contentclassattribute_id' => '183',
'contentobject_id' => '68',
'data_float' => '0.0',
'data_int' => '1045487555',
'data_text' => '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph>Content consumption is changing rapidly. An agile solution to distribute your content and empower your digital business model is key to success in every industry.</paragraph></section>',
'data_type_string' => 'ezxmltext',
'id' => '283',
'language_code' => 'eng-GB',
'language_id' => '2',
'sort_key_int' => '0',
'sort_key_string' => '',
'version' => '1',
],
[
'attribute_original_id' => '0',
'contentclassattribute_id' => '184',
'contentobject_id' => '68',
'data_float' => '0',
'data_int' => '1045487555',
'data_text' => '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph>eZ Publish Enterprise is the platform to make the omni-channel approach possible. A powerful presentation engine provides a multiplicity of websites and pages that display your content in a variety of renderings. A powerful API directly and simply integrates your content with any Web-enabled application on any device, including the iPad, iPhone or Android without ever interfering with or impacting the platform itself.</paragraph></section>',
'data_type_string' => 'ezxmltext',
'id' => '284',
'language_code' => 'eng-GB',
'language_id' => '2',
'sort_key_int' => '0',
'sort_key_string' => '',
'version' => '1',
],
[
'attribute_original_id' => '0',
'contentclassattribute_id' => '183',
'contentobject_id' => '69',
'data_float' => '0.0',
'data_int' => null,
'data_text' => '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph>Increasing the productivity of your content infrastructure, eZ Publish Enterprise provides you with powerful tools to create, automate and collaborate on content...</paragraph></section>',
'data_type_string' => 'ezxmltext',
'id' => '295',
'language_code' => 'eng-GB',
'language_id' => '2',
'sort_key_int' => '0',
'sort_key_string' => '',
'version' => '1',
],
[
'attribute_original_id' => 0,
'contentclassattribute_id' => 183,
'contentobject_id' => 69,
'data_float' => 0,
'data_int' => null,
'data_text' => '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph>version2</paragraph></section>',
'data_type_string' => 'ezxmltext',
'id' => '295',
'language_code' => 'eng-GB',
'language_id' => '2',
'sort_key_int' => 0,
'sort_key_string' => '',
'version' => 2,
],
[
'attribute_original_id' => 0,
'contentclassattribute_id' => 183,
'contentobject_id' => 69,
'data_float' => 0,
'data_int' => null,
'data_text' => '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/" xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/" xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"><paragraph>version2</paragraph></section>',
'data_type_string' => 'ezxmltext',
'id' => '296',
'language_code' => 'nor-NO',
'language_id' => '2',
'sort_key_int' => 0,
'sort_key_string' => '',
'version' => 2,
],
[
'attribute_original_id' => 0,
'contentclassattribute_id' => 183,
'contentobject_id' => 70,
'data_float' => 0,
'data_int' => null,
'data_text' => '<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"><title ezxhtml:level="2">header1text</title></section>',
'data_type_string' => 'ezrichtext',
'id' => '297',
'language_code' => 'nor-NO',
'language_id' => '2',
'sort_key_int' => 0,
'sort_key_string' => '',
'version' => 1,
],
[
'attribute_original_id' => 0,
'contentclassattribute_id' => 183,
'contentobject_id' => 70,
'data_float' => 0,
'data_int' => null,
'data_text' => '<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"><title ezxhtml:level="2">header1text</title></section>',
'data_type_string' => 'ezrichtext',
'id' => '298',
'language_code' => 'eng-GB',
'language_id' => '1',
'sort_key_int' => 0,
'sort_key_string' => '',
'version' => 1,
],
],
],
];
}

Expand Down
Expand Up @@ -153,5 +153,35 @@
'sort_key_string' => '',
'version' => 2,
],
10 => [
'attribute_original_id' => 0,
'contentclassattribute_id' => 183,
'contentobject_id' => 70,
'data_float' => 0,
'data_int' => null,
'data_text' => '<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"><title ezxhtml:level="2">header1text</title></section>',
'data_type_string' => 'ezrichtext',
'id' => '297',
'language_code' => 'nor-NO',
'language_id' => '2',
'sort_key_int' => 0,
'sort_key_string' => '',
'version' => 1,
],
11 => [
'attribute_original_id' => 0,
'contentclassattribute_id' => 183,
'contentobject_id' => 70,
'data_float' => 0,
'data_int' => null,
'data_text' => '<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"><title ezxhtml:level="2">header1text</title></section>',
'data_type_string' => 'ezrichtext',
'id' => '298',
'language_code' => 'eng-GB',
'language_id' => '1',
'sort_key_int' => 0,
'sort_key_string' => '',
'version' => 1,
],
],
];

0 comments on commit ba13194

Please sign in to comment.