Created
June 3, 2011 12:28
-
-
Save alpacaaa/1006265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Thanks Nick, ajax sounds like a good idea. Will implement this soon :)
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
Nice! You should probably also add the
EntryPreRender
andEntryPreEdit
delegates too, in case these manipulate the Entry objects.Batching could follow my Search Index, whereby it fires an AJAX request passing a page and per-page number. These entries are processed, and if there are more entries (the
total-pages
is less than thepage
parameter that is passed) then more AJAX requests are made. But this is a neat proof of concept :-)