Skip to content

Instantly share code, notes, and snippets.

@alpacaaa
Created June 3, 2011 12:28
Show Gist options
  • Save alpacaaa/1006265 to your computer and use it in GitHub Desktop.
Save alpacaaa/1006265 to your computer and use it in GitHub Desktop.
<?php
// file extensions/resave_entries/extension.driver.php
class extension_resave_entries extends Extension
{
public function about()
{
return array(
'name' => 'Resave entries',
'version' => '0.1',
'release-date' => '2011-06-03',
'author' => array(
'name' => 'Marco Sampellegrini',
'email' => 'm@rcosa.mp'
)
);
}
public function getSubscribedDelegates()
{
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'AddCustomPreferenceFieldsets',
)
);
}
public function AddCustomPreferenceFieldsets($context)
{
if (isset($_POST['action']['resave']))
{
$id = $_POST['resave-section'];
require_once TOOLKIT. '/class.entrymanager.php';
$engine = Symphony::Engine();
$em = new EntryManager($engine);
$sm = new SectionManager($engine);
$fm = new FieldManager($engine);
$ex = new ExtensionManager($engine);
$entries = $em->fetch($entry_id = null, $id);
$fields = $fm->fetch($field_id = null, $id);
$section = $sm->fetch($id);
if (!empty($entries)) $entries[0]->checkPostData(array());
foreach ($entries as $e)
{
$e->commit();
$ex->notifyMembers('EntryPostEdit', '/publish/edit/', array('section' => $section, 'entry' => $e, 'fields' => $fields));
}
Administration::instance()->Page->pageAlert(__('Entries resaved succesfully.'), Alert::SUCCESS);
}
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Resave entries')));
$span = new XMLElement('span', NULL, array('class' => 'frame'));
require_once TOOLKIT. '/class.sectionmanager.php';
$sm = new SectionManager(Symphony::Engine());
$sections = $sm->fetch();
$options = array();
foreach ($sections as $s)
{
$options[] = array(
$s->get('id'), false, $s->get('name')
);
}
$select = Widget::Select('resave-section', $options);
$span->appendChild($select);
$span->appendChild(new XMLElement('button', __('Resave Entries'), array_merge(array('name' => 'action[resave]', 'type' => 'submit'))));
$group->appendChild($span);
$context['wrapper']->appendChild($group);
}
}
@lewiswharf
Copy link

Awesome Marco! This will complement so many other extensions, including one I'm working on :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment