]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Added upgrade script to fetch thumbnails.
authorSem <sembrestels@riseup.net>
Sat, 25 Feb 2012 01:18:00 +0000 (02:18 +0100)
committerSem <sembrestels@riseup.net>
Sat, 25 Feb 2012 01:18:00 +0000 (02:18 +0100)
start.php
upgrades/2012022501.php [new file with mode: 0644]

index ff668f00cded075e6b6d0ebd51e216a2771bae2b..07ec618a0a652305caa41dea365a72ca5b34a2cd 100644 (file)
--- a/start.php
+++ b/start.php
@@ -67,6 +67,8 @@ function videolist_init() {
        elgg_register_action("videolist/add", "$actions_path/add.php");
        elgg_register_action("videolist/edit", "$actions_path/edit.php");
        elgg_register_action("videolist/delete", "$actions_path/delete.php");
+       
+       elgg_register_event_handler('upgrade', 'system', 'videolist_run_upgrades');
 }
 
 /**
@@ -262,3 +264,14 @@ function videolist_icon_url_override($hook, $type, $returnvalue, $params) {
                return "mod/videolist/graphics/videolist_icon_{$size}.png";
        }
 }
+
+/**
+ * Process upgrades for the videolist plugin
+ */
+function videolist_run_upgrades() {
+       $path = elgg_get_plugins_path() . 'videolist/upgrades/';
+       $files = elgg_get_upgrade_files($path);
+       foreach ($files as $file) {
+               include "$path{$file}";
+       }
+}
diff --git a/upgrades/2012022501.php b/upgrades/2012022501.php
new file mode 100644 (file)
index 0000000..815e10b
--- /dev/null
@@ -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");
+}