diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2013-12-29 20:45:58 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2013-12-29 20:45:58 -0200 |
commit | 97e689213ff4e829f251af526ed4e796a3cc2b71 (patch) | |
tree | b04d03ec56305041216b72328fc9b5afde27bc76 /mod/videolist/upgrades | |
parent | 0ab6351abb7a602d96c62b0ad35413c88113a6cf (diff) | |
parent | 69e2d8c5d8732042c9319aef1fdea45a82b63e42 (diff) | |
download | elgg-97e689213ff4e829f251af526ed4e796a3cc2b71.tar.gz elgg-97e689213ff4e829f251af526ed4e796a3cc2b71.tar.bz2 |
Merge branch 'master' into saravea
Conflicts:
.gitmodules
mod/admins
mod/assemblies
mod/audio_html5
mod/beechat
mod/crud
mod/elgg-activitystreams
mod/elggman
mod/elggpg
mod/favorites
mod/federated-objects
mod/friendly_time
mod/group_alias
mod/group_operators
mod/languages
mod/lightpics
mod/openid_client
mod/spotlight
mod/suicide
mod/tasks
mod/videolist
Diffstat (limited to 'mod/videolist/upgrades')
-rw-r--r-- | mod/videolist/upgrades/2012022501.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/mod/videolist/upgrades/2012022501.php b/mod/videolist/upgrades/2012022501.php new file mode 100644 index 000000000..f832c8033 --- /dev/null +++ b/mod/videolist/upgrades/2012022501.php @@ -0,0 +1,82 @@ +<?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', + 'limit' => 5, + 'order_by' => 'e.time_created asc', +)); + +// if not items, no upgrade required +if (!$items) { + return; +} + +/** + * Downloads the thumbnail and saves into data folder + * + * @param ElggObject $item + * @return bool + */ +function videolist_2012022501($item) { + require_once(elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php'); + + // get thumbnail image + $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(); + + // update properties + if ($item->url) { + $item->video_url = $item->url; + $item->deleteMetadata('url'); + } + if ($item->desc) { + $item->description = $item->desc; + $item->deleteMetadata('desc'); + $item->save(); + } + if ($item->embedurl) { + $item->deleteMetadata('embedurl'); + } + upgrade_change_subtype($item, 'videolist_item'); + + // update river + $options = array('object_guid' => $item->guid); + $river_items = elgg_get_river($options); + foreach($river_items as $river_item) { + if ($river_item->action_type == 'create') { + upgrade_update_river($river_item->id, 'river/object/videolist_item/create', $item->guid, 0); + } + } + + return true; +} +$previous_access = elgg_set_ignore_access(true); +$options = array( + 'type' => 'object', + 'subtype' => 'videolist', + '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"); +} |