Skip to content

Commit

Permalink
[+] Agregué la funcionalidad para evitar la duplicación de alias en a…
Browse files Browse the repository at this point in the history
…rticulos, categorias y tags
  • Loading branch information
alejoasotelo committed Jul 20, 2023
1 parent 5a0a5fe commit 49261bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
23 changes: 20 additions & 3 deletions plg_system_wp2joomla/src/AlejoASotelo/Adapter/K2Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use AlejoASotelo\Table\MigratorCategoryTable;
use AlejoASotelo\Table\CategoryFinalTable;
use AlejoASotelo\Table\TagFinalTable;
use Joomla\String\StringHelper;

class K2Adapter implements Wp2JoomlaAdapterInterface
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public function listArticles()
$article->id_adapter = $k2Article->id;
$article->catid = $categoryId;
$article->title = $k2Article->title;
$article->alias = \JFilterOutput::stringURLSafe($k2Article->title);
$article->alias = $this->generateNewAlias($articles, \JFilterOutput::stringURLSafe($k2Article->title), $article->id_adapter);
$article->published = $k2Article->published;
$article->state = $k2Article->published;
$article->language = '*';
Expand Down Expand Up @@ -141,7 +142,7 @@ public function listCategories()
$category->parent_id = 1;
$category->parent_id_adapter = $k2Category->parent_id ?: 1;
$category->title = $k2Category->name;
$category->alias = \JFilterOutput::stringURLSafe($k2Category->name);
$category->alias = $this->generateNewAlias($categories, \JFilterOutput::stringURLSafe($k2Category->name), $category->id_adapter);
$category->extension = 'com_content';
$category->published = 1;
$category->language = '*';
Expand Down Expand Up @@ -178,7 +179,7 @@ public function listTags()
$tag->parent_id = 1;
$tag->parent_id_adapter = $k2Category->parent_id ?: 1;
$tag->title = $k2Category->name;
$tag->alias = \JFilterOutput::stringURLSafe($k2Category->name);
$tag->alias = $this->generateNewAlias($tags, \JFilterOutput::stringURLSafe($k2Category->name), $tag->id_adapter);
$tag->description = '';
$tag->published = 1;
$tag->level = $k2Category->level;
Expand All @@ -196,6 +197,22 @@ public function listTags()
return $tags;
}

protected function generateNewAlias($items, $alias, $idAdapter)
{
$i = 0;
$len = count($items);
while ($i < $len) {
if ($items[$i]->alias == $alias && $items[$i]->id_adapter != $idAdapter) {
$alias = StringHelper::increment($alias, 'dash');
$i = -1;
}

$i++;
}

return $alias;
}

protected function getCategories()
{
$cacheId = 'getCategories';
Expand Down
12 changes: 11 additions & 1 deletion plg_system_wp2joomla/src/AlejoASotelo/Import/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AlejoASotelo\Adapter\Wp2JoomlaAdapterInterface;
use AlejoASotelo\Table\MigratorCategoryTable;
use AlejoASotelo\Table\CategoryFinalTable;
use AlejoASotelo\Table\TagFinalTable;

class Importer
{
Expand Down Expand Up @@ -101,6 +102,8 @@ public function importArticles()
* Undocumented function
*
* @param CategoryFinalTable $categoryFinal
* @param string $adapterName
*
* @return void
*/
protected function saveCategory($categoryFinal, $adapterName = 'wordpress')
Expand All @@ -114,6 +117,14 @@ protected function saveCategory($categoryFinal, $adapterName = 'wordpress')
return $categoryFinal;
}

/**
* Undocumented function
*
* @param TagFinalTable $tagFinal
* @param string $adapterName
*
* @return void
*/
protected function saveTag($tagFinal, $adapterName = 'k2')
{
$tagFinal->adapter = $adapterName;
Expand Down Expand Up @@ -141,5 +152,4 @@ protected function saveArticle($articleFinal, $adapterName = 'wordpress')

return $articleFinal;
}

}

0 comments on commit 49261bc

Please sign in to comment.