]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixing blog upgrades for excerpt.
authorBrett Profitt <brett.profitt@gmail.com>
Thu, 25 Aug 2011 17:34:52 +0000 (10:34 -0700)
committerBrett Profitt <brett.profitt@gmail.com>
Thu, 25 Aug 2011 17:34:52 +0000 (10:34 -0700)
mod/blog/start.php

index b9911aa74fd2589e678a94c73ac0d5916a013171..d00196bfda6936600023a7c8586c4a47feb07067 100644 (file)
@@ -225,11 +225,37 @@ function blog_ecml_views_hook($hook, $entity_type, $return_value, $params) {
 }
 
 /**
- * When upgrading, check if the ElggBlog class has been registered as this
- * was added in Elgg 1.8
+ * Upgrade from 1.7 to 1.8.
  */
-function blog_run_upgrades() {
-       if (!update_subtype('object', 'blog', 'ElggBlog')) {
-               add_subtype('object', 'blog', 'ElggBlog');
+function blog_run_upgrades($event, $type, $details) {
+       $blog_upgrade_version = get_plugin_setting('upgrade_version', 'blogs');
+
+       if (!$blog_upgrade_version) {
+                // When upgrading, check if the ElggBlog class has been registered as this
+                // was added in Elgg 1.8
+               if (!update_subtype('object', 'blog', 'ElggBlog')) {
+                       add_subtype('object', 'blog', 'ElggBlog');
+               }
+
+               // only run this on the first migration to 1.8
+               if ($details->to >= 2011061200) {
+                       // add excerpt to all blogs that don't have it.
+                       $ia = elgg_set_ignore_access(true);
+                       $options = array(
+                               'type' => 'object',
+                               'subtype' => 'blog'
+                       );
+
+                       $blogs = new ElggBatch($options);
+                       foreach ($blogs as $blog) {
+                               if (!$blog->excerpt) {
+                                       $blog->excerpt = elgg_get_excerpt($blog->description);
+                               }
+                       }
+
+                       elgg_set_ignore_access($ia);
+               }
+
+               elgg_set_plugin_setting('upgrade_version', 1, 'blogs');
        }
 }