Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Podcast Manager Batch Resave Script
<?php
/**
* Podcast Manager Batch Save Script
*
* @copyright Copyright (C) 2014 Michael Babker. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License Version 2 or Later
*/
// Set flag that this is a parent file.
const _JEXEC = 1;
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
// Import the configuration.
require_once JPATH_CONFIGURATION . '/configuration.php';
/**
* Podcast Manager Batch Save Script
*
* @since 1.0
*/
class PodcastManagerBatchSave extends JApplicationCli
{
/**
* Method to run the application routines.
*
* @return void
*
* @since 1.0
*/
public function doExecute()
{
// Import the Podcast Manager table path to find the classes
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_podcastmanager/tables');
$db = JFactory::getDbo();
// First let's get all of the IDs for Podcast Manager feeds
$db->setQuery(
$db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__podcastmanager_feeds'))
);
try
{
$feeds = $db->loadObjectList();
}
catch (RuntimeException $e)
{
$this->out('Error retrieving Podcast Manager feed IDs: ' . $e->getMessage());
$this->close();
}
// Loop through each feed and resave it
foreach ($feeds as $feed)
{
/** @type PodcastManagerTableFeed $table */
$table = JTable::getInstance('Feed', 'PodcastManagerTable', array('dbo' => $db));
$table->load($feed->id);
try
{
$table->store();
}
catch (Exception $e)
{
$this->out('Error storing Podcast Manager feed ID ' . $feed->id . ': ' . $e->getMessage());
exit();
}
}
// Now let's get all of the podcasts
$db->setQuery(
$db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__podcastmanager'))
);
try
{
$podcasts = $db->loadObjectList();
}
catch (RuntimeException $e)
{
$this->out('Error retrieving Podcast Manager podcast IDs: ' . $e->getMessage());
$this->close();
}
// Loop through each podcast and resave it
foreach ($podcasts as $podcast)
{
/** @type PodcastManagerTablePodcast $table */
$table = JTable::getInstance('Podcast', 'PodcastManagerTable', array('dbo' => $db));
$table->load($podcast->id);
try
{
$table->store();
}
catch (Exception $e)
{
$this->out('Error storing Podcast Manager podcast ID ' . $podcast->id . ': ' . $e->getMessage());
exit();
}
}
}
}
// Global exception handler, this way we can get decent messages if need be
try
{
JApplicationCli::getInstance('PodcastManagerBatchSave')->execute();
}
catch (Exception $e)
{
fwrite(STDOUT, "\nERROR: " . $e->getMessage() . "\n");
fwrite(STDOUT, "\n" . $e->getTraceAsString() . "\n");
exit($e->getCode() ? : 255);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.