How to Migrate Frontpage SlideShow from Version 2.0 to Version 3.5

Ask any programmer what kind of work he dreads (and dislikes) most, and he’ll invariably answer you: “It has to be manual data entry”. Since we are programmers, then that answer applies to us as well. But hey, life isn’t always about doing the things that you love, sometimes, you’ll need to do things that you really don’t love, for the greater good. OK, let’s get not too philosiphical here, and let us explain to you what happened yesterday afternoon…

We were migrating a Joomla website for a New York photographer; we thought that we were almost done since the only thing left to do was to migrate his slideshows. Our client was using Frontpage SlideShow (by JoomlaWorks) and he had nearly 3,000 slides spread over something like a hundred categories. We weren’t worried, because we knew that JoomlaWorks products were solid and extremely easy to migrate (K2 is a great example). However, after doing an extensive search, we discovered that the advice that JoomlaWorks gives to its users is to migrate the SlideShow component manually! In other words, a human must create all the categories, one by one, and then create the slides, also one by one, until he reaches retirement age or until the project is done. That’s not good! What’s even worse is that no one has developed a script to automate that!

Now, we discussed this project for a while amongst ourselves: If we want to create the categories and the slides manually, and assuming it takes 1 minute per category and 5 minutes per slide (one needs to download the slide from the old website and re-upload it to the new website), then it’ll take us 100 minutes for the categories and 15,000 minutes for the slides. In other words, it’ll take us 252 hours of pure, uninterrupted work to migrate the slideshow, way over the 40 hours we agreed on with the client to migrate the whole Joomla website! Since our fees were fixed (we can’t charge the client for more than 40 hours) and since we don’t have that much time on our hands (and also since we really, really, don’t like doing manual work) we had to develop a solution to migrate the slideshows automatically. And so we did!

We thought – what if we perform the same actions performed when creating a category and a slide from Joomla’s backend, but in a loop? In other words, what if we modify the models for the category and the slide in order to migrate the data. That idea worked, and the proof is below.

How we migrated Frontpage SlideShow’s categories

In order to migrate the categories, we opened the model file category.php located under the administrator/components/com_fpss/models/ folder. We changed the save() function to the below:

function save()
{
	$sql = "SELECT * FROM jos_fpss_categories";
	$db->setQuery($sql);
	$arrCategories = $db->loadAssocList();
	for ($i = 0; $i < count($arrCategories ); $i++){
		$row = JTable::getInstance('category', 'FPSS');
		
		$data = $this->getState('data');
		$data['title']= $arrCategories [$i]['name'];

		if (!$row->bind($data))
		{
			$this->setError($row->getError());
			return false;
		}
		if (!$row->check())
		{
			$this->setError($row->getError());
			return false;
		}
		if (!$row->id)
		{
			$row->ordering = $row->getNextOrder();
		}
		if (!$row->store())
		{
			$this->setError($row->getError());
			return false;
		}
	}
}

We then uploaded the file and we created a dummy category in FPSS SlideShow, and we clicked on the “Save” button, and that migrated all the categories! Not bad! We immediately reverted back the category.php to what it was when we were done.

How we migrated the Frontpage SlideShow’s slides

We employed the same principle above for migrating slides, but with a twist since the way the images are saved in the 3.5 version differs greatly from that in the 2.0 version. So, we first copied the images folder from the components/com_fpss/ folder from the old website to the same location on the new website (e.g. the components/com_fpss/images on the new website) to ensure that the new website has access to these images.

We then modified the save() function in the slide.php model file (also located under under the administrator/components/com_fpss/models/ folder) to the following:

function save()
{
	$db = $this->getDBO();
	
	$sql = "SELECT * FROM jos_fpss_slides WHERE state=1 ORDER BY catid ASC, ordering ASC";
	$db->setQuery($sql);
	$arrSlides = $db->loadAssocList();
	
	$k = 4;
	for ($i = 0; $i < count($arrSlides); $i++){
		++$k;
		$row = JTable::getInstance('slide', 'FPSS');
		$config = JFactory::getConfig();
		$tzoffset = version_compare(JVERSION, '3.0', 'ge') ? $config->get('offset') : $config->getValue('config.offset');
		$data = $this->getState('data');
		$data['title']= $arrSlides[$i]['name'];
		$data['catid']= $arrSlides[$i]['catid'];

		$filename = $k.'_'.md5('Image'.$k);
		copy('/'.$arrSlides[$i]['path'], '/media/com_fpss/src/'.$filename.'_s.jpg');
		copy('/'.$arrSlides[$i]['path'], '/media/com_fpss/cache/'.$filename.'_m.jpg');
		copy('/'.$arrSlides[$i]['path'], '/media/com_fpss/cache/'.$filename.'_p.jpg');
		copy('/'.$arrSlides[$i]['thumb'], '/media/com_fpss/cache/'.$filename.'_t.jpg');
		
		if (!$row->bind($data))
		{
			$this->setError($row->getError());
			return false;
		}
		if (!$row->check())
		{
			$this->setError($row->getError());
			return false;
		}

		$date = JFactory::getDate($row->publish_up, $tzoffset);
		$row->publish_up = version_compare(JVERSION, '1.6.0', '<') ? $date->toMySQL() : $date->toSql();
		if (trim($row->publish_down) == JText::_('FPSS_NEVER') || trim($row->publish_down) == '')
		{
			$row->publish_down = $db->getNullDate();
		}
		else
		{
			$date = JFactory::getDate($row->publish_down, $tzoffset);
			$row->publish_down = version_compare(JVERSION, '1.6.0', '<') ? $date->toMySQL() : $date->toSql();
		}
		$now = JFactory::getDate('now', $tzoffset);
		$user = JFactory::getUser();
		if ($row->id)
		{
			$row->modified = version_compare(JVERSION, '1.6.0', '<') ? $now->toMySQL() : $now->toSql();
			$row->modified_by = $user->get('id');
		}
		else
		{
			$row->created = version_compare(JVERSION, '1.6.0', '<') ? $now->toMySQL() : $now->toSql();
			$row->created_by = $user->get('id');
			$row->ordering = $row->getNextOrder('catid = '.$row->catid);
			$row->featured_ordering = $row->getNextOrder('featured=1');
			$row->hits = 0;
		}

		if ($row->referenceType == 'custom')
		{
			$row->custom = $data['reference'];
		}

		if (!$row->store())
		{
			$this->setError($row->getError());
			return false;
		}
	}
}

We then created a dummy slide in the backend and saved it. This migrated all the slides, including the images! The issue was solved and we reverted the slide.php model file back to what it was before!

Some assumptions in our guide above:

  • The IDs of the categories are sequential on the old website and they start at number 2.
  • Both the old website and the new website use the same database, but the old Joomla website uses jos_ as the table prefix, while the new website uses a custom table prefix.

  • Your have not added/deleted any slides manually to FPSS on the new website. In short, you only have 4 test slides that came with the installation.

  • You are a good, careful developer or you have access to one.

If the above assumptions do not hold true for your Joomla website, then most certainly our method will not work, and you will need to contact us to migrate the slideshow for you. Please note that our very reasonable fees apply.

No comments yet.

Leave a comment