Skip to content

Commit

Permalink
Miscellaneous fixes, implemented more imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ian_maclennan committed Feb 5, 2011
1 parent b83f816 commit 6980cc2
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 22 deletions.
10 changes: 6 additions & 4 deletions administrator/components/com_onward/helpers/importer/adapter.php
Expand Up @@ -25,6 +25,8 @@ abstract class OnwardImporterAdapter extends JPlugin
*/
protected $context;

protected $site_id;

/**
* Method to get the adapter state and push it into the importer.
*
Expand All @@ -34,15 +36,15 @@ abstract class OnwardImporterAdapter extends JPlugin
public function onStartImport()
{
// Get the number of data items.
$site_id = OnwardImporter::$site_id;
$this->site_id = OnwardImporter::$site_id;

$total = (int)$this->getContentCount();
$table = JTable::getInstance('SiteState', 'OnwardTable');
if ($table->load(array('site_id' => $site_id, 'asset' => $this->context))) {
if ($table->load(array('site_id' => $this->site_id, 'asset' => $this->context))) {
$table->total = $total;
$table->offset = 0;
} else {
$table->site_id = $site_id;
$table->site_id = $this->site_id;
$table->asset = $this->context;
$table->total = $total;
$table->offset = 0;
Expand Down Expand Up @@ -82,7 +84,7 @@ protected function checkDependencies()
// Check to see if we are ready to process these items
foreach ($dependencies AS $dependency)
{
if ($states[$dependency]['limit'] != $states[$dependency]['offset']) {
if (OnwardImporter::$state[$dependency]->total != OnwardImporter::$state[$dependency]->offset) {
$dependencies_met = false;
}
}
Expand Down
23 changes: 15 additions & 8 deletions administrator/components/com_onward/helpers/importer/importer.php
Expand Up @@ -101,24 +101,31 @@ public static function resetState()
$db->query();
}

public static function map($data)
public static function map($asset, $original_id, $new_id, $site_id = false)
{
if (!isset(self::$mapTable)) {
self::$mapTable = JTable::getInstance('DataMap', 'OnwardTable');
}

$mapper = self::$mapTable;
$mapper->site_id = self::$site_id;
$mapper->asset = $data->asset;
$mapper->original_id = $data->original_id;
$mapper->new_id = $data->new_id;
$mapper->site_id = $site_id ? $site_id : self::$site_id;
$mapper->asset = $asset;
$mapper->original_id = $original_id;
$mapper->new_id = $new_id;
$mapper->store();
}

public static function getMappedId($asset, $original_id)
public static function getMappedId($asset, $original_id, $site_id = false)
{
$site_id = $site_id ? $site_id : self::$site_id;

$db = JFactory::getDbo();
$query = 'SELECT new_id FROM #__onward_data_map WHERE original_id = '.(int)$original_id.' AND site_id = '.(int)self::$site_id.' AND asset = \''.$asset.'\'';
$query = new JDatabaseQuery();
$query->select('new_id');
$query->from('#__onward_data_map');
$query->where('original_id = '.(int)$original_id);
$query->where('site_id = '.(int)$site_id);
$query->where('asset = '.$db->quote($asset));
$db->setQuery($query);
$id = $db->loadResult();
return $id;
Expand Down
42 changes: 41 additions & 1 deletion plugins/onward/joomla15_categories/joomla15_categories.php
Expand Up @@ -41,15 +41,55 @@ protected function getListQuery($sql = null)
return $sql;
}

protected function getDependencies()
{
return array('jos_sections');
}

/**
* Method to import an item.
*
* @param object The item to import.
* @return boolean True on success.
* @throws Exception on database error.
*/
protected function import($oldUser)
protected function import($oldCategory)
{
$catObject = JTable::getInstance('category');

$parent = OnwardImporter::getMappedId('jos_sections', $oldCategory->section);
$catObject->id = 0;
$catObject->parent_id = $parent;
$catObject->setLocation($parent, 'last-child');
$catObject->level = 2;
$catObject->path = $parent.'/'.$oldCategory->alias;
$catObject->extension = 'com_content';
$catObject->title = $oldCategory->title;
$catObject->alias = $oldCategory->alias;
$catObject->description = $oldCategory->description;
$catObject->published = $oldCategory->published;
$catObject->checked_out = 0;
$catObject->checked_out_time = '0000-00-00 00:00:00';
$catObject->access = $oldCategory->access; // TODO figure out mapping
$catObject->params = $oldCategory->params;
$catObject->metadesc = '';
$catObject->metakey = '';
$catObject->metadata = '';
$catObject->created_user_id = 0;
$catObject->created_time = '0000-00-00 00:00:00';
$catObject->modified_user_id = 0;
$catObject->modified_time = '0000-00-00 00:00:00';
$catObject->hits = $oldCategory->count; // TODO check what count does
$catObject->language = '*';
// TODO - deal with ordering

$result = $catObject->store();

if ($result) {
OnwardImporter::map($this->context, $oldCategory->id, $catObject->id);
return true;
} else {
return false;
}
}
}
53 changes: 52 additions & 1 deletion plugins/onward/joomla15_content/joomla15_content.php
Expand Up @@ -25,6 +25,11 @@ class plgOnwardJoomla15_Content extends OnwardImporterAdapter
*/
protected $context = 'jos_content';

protected function getDependencies()
{
return array('jos_categories', 'jos_users');
}

/**
* Method to get the SQL query used to retrieve the list of content items.
*
Expand All @@ -48,7 +53,53 @@ protected function getListQuery($sql = null)
* @return boolean True on success.
* @throws Exception on database error.
*/
protected function import($oldUser)
protected function import($oldContent)
{
$contentObject = JTable::getInstance('content');

$parent = OnwardImporter::getMappedId('jos_categories', $oldContent->catid);
$contentObject->id = 0;
$contentObject->title = $oldContent->title;
$contentObject->alias = $oldContent->alias;
$contentObject->title_alias = $oldContent->title_alias;
$contentObject->introtext = $oldContent->introtext;
$contentObject->fulltext = $oldContent->fulltext;
$contentObject->state = $oldContent->state;
$contentObject->sectionid = 0;
$contentObject->mask = 0;
$contentObject->catid = $parent;
$contentObject->created = $oldContent->created;
$contentObject->created_by = OnwardImporter::getMappedId('jos_users', $oldContent->created_by);
$contentObject->created_by_alias = $oldContent->created_by_alias;
$contentObject->modified = $oldContent->modified;
$contentObject->modified_by = OnwardImporter::getMappedId('jos_users', $oldContent->modified_by);
$contentObject->checked_out_time = '0000-00-00 00:00:00';
$contentObject->checked_out = 0;
$contentObject->publish_up = $oldContent->publish_up;
$contentObject->publish_down = $oldContent->publish_down;
$contentObject->images = ''; //$oldContent->images;
$contentObject->urls = ''; //$oldContent->urls;
$contentObject->attribs = $oldContent->attribs;
$contentObject->version = $oldContent->version;
$contentObject->parentid = 0;
$contentObject->ordering = $oldContent->ordering;
$contentObject->metakey = $oldContent->metakey;
$contentObject->metadesc = $oldContent->metadesc;
$contentObject->access = $oldContent->access + 1; // TODO Map access
$contentObject->hits = $oldContent->hits;
$contentObject->metadata = $oldContent->metadata;
$contentObject->featured = 0; // we will have to fix this later when we get the featured table
$contentObject->language = '*';
$contentObject->xreference = '';

$result = $contentObject->store();

if ($result) {
OnwardImporter::map($this->context, $oldContent->id, $contentObject->id);
return true;
} else {
return false;
}

}
}
Expand Up @@ -25,6 +25,11 @@ class plgOnwardJoomla15_Content_Frontpage extends OnwardImporterAdapter
*/
protected $context = 'jos_content_frontpage';

protected function getDependencies()
{
return array('jos_content');
}

/**
* Method to get the SQL query used to retrieve the list of content items.
*
Expand All @@ -48,7 +53,28 @@ protected function getListQuery($sql = null)
* @return boolean True on success.
* @throws Exception on database error.
*/
protected function import($oldUser)
protected function import($oldContentFrontpage)
{
JTable::addIncludePath(JPATH_ADMINISTRATOR.'/components/com_content/tables');
$contentFrontpageObject = JTable::getInstance('Featured', 'ContentTable');

$contentFrontpageObject->content_id = OnwardImporter::getMappedId('jos_content_frontpage', $oldContentFrontpage->content_id);
$contentFrontpageObject->ordering = $oldContentFrontpage->ordering;

$result = $contentFrontpageObject->store();

$contentObject = JTable::getInstance('Content');

$contentObject->load($contentFrontpageObject->content_id);
$contentObject->featured = 1;
$contentObject->store();

if ($result) {
OnwardImporter::map($this->context, $oldContentFrontpage->id, $contentFrontpageObject->id);
return true;
} else {
return false;
}

}
}
36 changes: 35 additions & 1 deletion plugins/onward/joomla15_sections/joomla15_sections.php
Expand Up @@ -48,8 +48,42 @@ protected function getListQuery($sql = null)
* @return boolean True on success.
* @throws Exception on database error.
*/
protected function import($oldUser)
protected function import($oldSection)
{
$catObject = JTable::getInstance('category');

$catObject->id = 0;
$catObject->parent_id = 1;
$catObject->setLocation(1, 'last-child');
$catObject->level = 1;
$catObject->path = $oldSection->alias;
$catObject->extension = 'com_content';
$catObject->title = $oldSection->title;
$catObject->alias = $oldSection->alias;
$catObject->published = $oldSection->published;
$catObject->note = '';
$catObject->description = $oldSection->description;
$catObject->checked_out = 0;
$catObject->checked_out_time = '0000-00-00 00:00:00';
$catObject->access = $oldSection->access + 1; // TODO figure out mapping
$catObject->params = $oldSection->params;
$catObject->metadesc = '';
$catObject->metakey = '';
$catObject->metadata = '';
$catObject->created_user_id = 0;
$catObject->created_time = '0000-00-00 00:00:00';
$catObject->modified_user_id = 0;
$catObject->modified_time = '0000-00-00 00:00:00';
$catObject->hits = $oldSection->count; // TODO check what count does
$catObject->language = '*';

$result = $catObject->store();

if ($result) {
OnwardImporter::map($this->context, $oldSection->id, $catObject->id);
return true;
} else {
return false;
}
}
}
10 changes: 4 additions & 6 deletions plugins/onward/joomla15_users/joomla15_users.php
Expand Up @@ -50,9 +50,6 @@ protected function getListQuery($sql = null)
*/
protected function import($oldUser)
{
$db = JFactory::getDBO();

//$userObject = JUser::getInstance(0);
$userObject = JTable::getInstance('user');

$userObject->id = 0;
Expand All @@ -71,9 +68,10 @@ protected function import($oldUser)
$result = $userObject->store();

if ($result) {
$newId = $userObject->id;
$db->setQuery('INSERT INTO #__onward_data_map (site_id, asset, original_id, new_id) VALUES (13, \'jos_users\', '.$oldUser->id.', '.$userObject->id.')');
$db->query();
OnwardImporter::map($this->context, $oldUser->id, $userObject->id);
return true;
} else {
return false;
}
}
}

0 comments on commit 6980cc2

Please sign in to comment.