Skip to content

Commit

Permalink
Fix #29 Uncategorized items (no category) get moved into wrong category
Browse files Browse the repository at this point in the history
This also fixes a bug where articles having a missing category get lost.
  • Loading branch information
mahagr committed Mar 21, 2012
1 parent ebce57f commit 7390b87
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions trunk/admin/includes/migrate_content.php
Expand Up @@ -45,15 +45,25 @@ protected function &getSourceData()


$rows = parent::getSourceData( $rows = parent::getSourceData(
'`id`, `title`, `alias`, `title_alias`, `introtext`, `fulltext`, `state`, ' '`id`, `title`, `alias`, `title_alias`, `introtext`, `fulltext`, `state`, '
.'`mask`, o.new AS catid, `created`, `created_by`, `created_by_alias`, ' .'`mask`, `catid`, `created`, `created_by`, `created_by_alias`, '
.'`modified`, `modified_by`, `checked_out`, `checked_out_time`, `publish_up`, `publish_down`, ' .'`modified`, `modified_by`, `checked_out`, `checked_out_time`, `publish_up`, `publish_down`, '
.'`images`, `urls`, `attribs`, `version`, `parentid`, `ordering`, `metakey`, `metadesc`, ' .'`images`, `urls`, `attribs`, `version`, `parentid`, `ordering`, `metakey`, `metadesc`, '
.'`access`, `hits` ', .'`access`, `hits` ',
'LEFT JOIN jupgrade_categories AS o ON o.old = c.catid', null,
$where, null,
'id' 'id'
); );


// Get category mapping
$query = "SELECT * FROM jupgrade_categories WHERE section REGEXP '^[\\-\\+]?[[:digit:]]*\\.?[[:digit:]]*$' AND old>0";
$this->db_new->setQuery($query);
$catidmap = $this->db_new->loadObjectList('old');

// Find uncategorised category id
$query = "SELECT id FROM #__categories WHERE extension='com_content' AND path='uncategorised' LIMIT 1";
$this->db_new->setQuery($query);
$defaultId = $this->db_new->loadResult();

// Do some custom post processing on the list. // Do some custom post processing on the list.
foreach ($rows as &$row) foreach ($rows as &$row)
{ {
Expand All @@ -65,6 +75,9 @@ protected function &getSourceData()
if ($row['state'] == -1) { if ($row['state'] == -1) {
$row['state'] = 2; $row['state'] = 2;
} }

// Map catid
$row['catid'] = isset($catidmap[$row['catid']]) ? $catidmap[$row['catid']]->new : $defaultId;


/* /*
* Prevent JGLOBAL_ARTICLE_MUST_HAVE_TEXT error * Prevent JGLOBAL_ARTICLE_MUST_HAVE_TEXT error
Expand Down

0 comments on commit 7390b87

Please sign in to comment.