allow for skipping normalize checks and return raw metadata

This commit is contained in:
John Bintz 2009-11-14 12:46:30 -05:00
parent 5d90e9746e
commit faacafcaf1
2 changed files with 18 additions and 2 deletions

View File

@ -24,13 +24,17 @@ class ComicPressComicPost {
/**
* Normalize the ordering of attachments in this post.
* If images have beed added or removed, intelligently update the metadata.
* TODO Allow skipping of normalization if performance is needed
* @param boolean $skip_checks If true, only return the post metadata, assuming that everything is correct. Do not use anywhere in the admin interface!
* @return array The normalized data, which is also written to the post's metadata if $skip_checks is false.
*/
function normalize_ordering() {
function normalize_ordering($skip_checks = false) {
$attachments = $this->get_attachments();
if (is_array($attachments)) {
$new_ordering = array();
$current_ordering = get_post_meta($this->post->ID, 'image-ordering', true);
if ($skip_checks) { return $current_ordering; }
if (!is_array($current_ordering)) { $current_ordering = array(); }
$all_current_ids = array();

View File

@ -75,6 +75,18 @@ class ComicPressComicPostTest extends PHPUnit_Framework_TestCase {
}
}
function testNormalizeOrderingSkipChecks() {
$p = $this->getMock('ComicPressComicPost', array('get_attachments'));
$p->expects($this->once())->method('get_attachments')->will($this->returnValue(array('test', 'test2')));
$p->post = (object)array('ID' => 1);
update_post_meta(1, 'image-ordering', array('test' => array('enabled' => true)));
$this->assertEquals(array('test' => array('enabled' => true)), $p->normalize_ordering(true));
$this->assertEquals(array('test' => array('enabled' => true)), get_post_meta(1, 'image-ordering', true));
}
function providerTestUpdatePostMediaData() {
return array(
array(