diff options
author | Sem <sembrestels@riseup.net> | 2012-02-25 02:18:00 +0100 |
---|---|---|
committer | Sem <sembrestels@riseup.net> | 2012-02-25 02:18:00 +0100 |
commit | f1a0a4d5aa28753620552df9d5e88bd983d0aca4 (patch) | |
tree | 916f0f335ac1a0716b321c229ccd9ba7511bf284 /upgrades/2012022501.php | |
parent | 8ccd45aa77d290906fd42dcf5520a434303d4f68 (diff) | |
download | elgg-f1a0a4d5aa28753620552df9d5e88bd983d0aca4.tar.gz elgg-f1a0a4d5aa28753620552df9d5e88bd983d0aca4.tar.bz2 |
Added upgrade script to fetch thumbnails.
Diffstat (limited to 'upgrades/2012022501.php')
-rw-r--r-- | upgrades/2012022501.php | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/upgrades/2012022501.php b/upgrades/2012022501.php new file mode 100644 index 000000000..815e10b62 --- /dev/null +++ b/upgrades/2012022501.php @@ -0,0 +1,70 @@ +<?php +/** + * Download the video thumbnail in the server and link it to video + * + * First determine if the upgrade is needed and then if needed, batch the update + */ + +$items = elgg_get_entities(array( + 'type' => 'object', + 'subtype' => 'videolist_item', + 'limit' => 5, + 'order_by' => 'e.time_created asc', +)); + +// if not items, no upgrade required +if (!$items) { + return; +} + +// if all five of the items have empty thumbnails, we need to upgrade +foreach ($items as $item) { + if ($item->thumbnail === true) { + return; + } +} + + +/** + * Downloads the thumbnail and saves into data folder + * + * @param ElggObject $item + */ +function videolist_2012022501($item) { + + // do not upgrade videos that have already been upgraded + if ($item->thumbnail === true) { + return true; + } + + $thumbnail = file_get_contents($item->thumbnail); + if (!$thumbnail) { + return false; + } + + $prefix = "videolist/" . $item->guid; + $filehandler = new ElggFile(); + $filehandler->owner_guid = $item->owner_guid; + $filehandler->setFilename($prefix . ".jpg"); + $filehandler->open("write"); + $filehandler->write($thumbnail); + $filehandler->close(); + + $item->thumbnail = true; + return true; +} + +$previous_access = elgg_set_ignore_access(true); +$options = array( + 'type' => 'object', + 'subtype' => 'videolist_item', + 'limit' => 0, +); +$batch = new ElggBatch('elgg_get_entities', $options, 'videolist_2012022501', 100); +elgg_set_ignore_access($previous_access); + +if ($batch->callbackResult) { + error_log("Elgg videolist upgrade (2012022501) succeeded"); +} else { + error_log("Elgg videolist upgrade (2012022501) failed"); +} |