2012022501.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Download the video thumbnail in the server and link it to video
  4. *
  5. * First determine if the upgrade is needed and then if needed, batch the update
  6. */
  7. $items = elgg_get_entities(array(
  8. 'type' => 'object',
  9. 'subtype' => 'videolist',
  10. 'limit' => 5,
  11. 'order_by' => 'e.time_created asc',
  12. ));
  13. // if not items, no upgrade required
  14. if (!$items) {
  15. return;
  16. }
  17. /**
  18. * Downloads the thumbnail and saves into data folder
  19. *
  20. * @param ElggObject $item
  21. * @return bool
  22. */
  23. function videolist_2012022501($item) {
  24. require_once(elgg_get_plugins_path() . 'upgrade-tools/lib/upgrade_tools.php');
  25. // get thumbnail image
  26. $thumbnail = file_get_contents($item->thumbnail);
  27. if (!$thumbnail) {
  28. return false;
  29. }
  30. $prefix = "videolist/" . $item->guid;
  31. $filehandler = new ElggFile();
  32. $filehandler->owner_guid = $item->owner_guid;
  33. $filehandler->setFilename($prefix . ".jpg");
  34. $filehandler->open("write");
  35. $filehandler->write($thumbnail);
  36. $filehandler->close();
  37. // update properties
  38. if ($item->url) {
  39. $item->video_url = $item->url;
  40. $item->deleteMetadata('url');
  41. }
  42. if ($item->desc) {
  43. $item->description = $item->desc;
  44. $item->deleteMetadata('desc');
  45. $item->save();
  46. }
  47. if ($item->embedurl) {
  48. $item->deleteMetadata('embedurl');
  49. }
  50. upgrade_change_subtype($item, 'videolist_item');
  51. // update river
  52. $options = array('object_guid' => $item->guid);
  53. $river_items = elgg_get_river($options);
  54. foreach($river_items as $river_item) {
  55. if ($river_item->action_type == 'create') {
  56. upgrade_update_river($river_item->id, 'river/object/videolist_item/create', $item->guid, 0);
  57. }
  58. }
  59. return true;
  60. }
  61. $previous_access = elgg_set_ignore_access(true);
  62. $options = array(
  63. 'type' => 'object',
  64. 'subtype' => 'videolist',
  65. 'limit' => 0,
  66. );
  67. $batch = new ElggBatch('elgg_get_entities', $options, 'videolist_2012022501', 100);
  68. elgg_set_ignore_access($previous_access);
  69. if ($batch->callbackResult) {
  70. error_log("Elgg videolist upgrade (2012022501) succeeded");
  71. } else {
  72. error_log("Elgg videolist upgrade (2012022501) failed");
  73. }