<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [1706] trunk:
  Added upgrade code to move old group avatars to the correct new folders so they are not lost in 1
 .1.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>1706</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-08-26 17:25:17 +0000 (Wed, 26 Aug 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Added upgrade code to move old group avatars to the correct new folders so they are not lost in 1.1.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsbpgroupsclassesphp">trunk/bp-groups/bp-groups-classes.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsbpgroupsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-classes.php (1705 => 1706)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-classes.php        2009-08-26 16:21:57 UTC (rev 1705)
+++ trunk/bp-groups/bp-groups-classes.php        2009-08-26 17:25:17 UTC (rev 1706)
</span><span class="lines">@@ -418,17 +418,17 @@
</span><span class="cx">                         
</span><span class="cx">                         switch ( $sort_by ) {
</span><span class="cx">                                 default:
</span><del>-                                        $sql = $wpdb-&gt;prepare( &quot;SELECT g.id as group_id, g.slug FROM {$bp-&gt;groups-&gt;table_name} g {$public_sql} {$hidden_sql} {$order_sql} {$pag_sql}&quot; );         
</del><ins>+                                        $sql = $wpdb-&gt;prepare( &quot;SELECT * FROM {$bp-&gt;groups-&gt;table_name} g {$public_sql} {$hidden_sql} {$order_sql} {$pag_sql}&quot; );         
</ins><span class="cx">                                         break;
</span><span class="cx">                                 case 'members':
</span><del>-                                        $sql = $wpdb-&gt;prepare( &quot;SELECT g.id as group_id, g.slug FROM {$bp-&gt;groups-&gt;table_name} g, {$bp-&gt;groups-&gt;table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'total_member_count' {$hidden_sql} {$public_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}&quot; ); 
</del><ins>+                                        $sql = $wpdb-&gt;prepare( &quot;SELECT * FROM {$bp-&gt;groups-&gt;table_name} g, {$bp-&gt;groups-&gt;table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'total_member_count' {$hidden_sql} {$public_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}&quot; ); 
</ins><span class="cx">                                         break;
</span><span class="cx">                                 case 'last_active':
</span><del>-                                        $sql = $wpdb-&gt;prepare( &quot;SELECT g.id as group_id, g.slug FROM {$bp-&gt;groups-&gt;table_name} g, {$bp-&gt;groups-&gt;table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'last_activity' {$hidden_sql} {$public_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}&quot; ); 
</del><ins>+                                        $sql = $wpdb-&gt;prepare( &quot;SELECT * FROM {$bp-&gt;groups-&gt;table_name} g, {$bp-&gt;groups-&gt;table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'last_activity' {$hidden_sql} {$public_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}&quot; ); 
</ins><span class="cx">                                         break;
</span><span class="cx">                         }
</span><span class="cx">                 } else {
</span><del>-                        $sql = $wpdb-&gt;prepare( &quot;SELECT g.id as group_id, g.slug FROM {$bp-&gt;groups-&gt;table_name} g {$public_sql} {$hidden_sql} {$order_sql} {$pag_sql}&quot; );         
</del><ins>+                        $sql = $wpdb-&gt;prepare( &quot;SELECT * FROM {$bp-&gt;groups-&gt;table_name} g {$public_sql} {$hidden_sql} {$order_sql} {$pag_sql}&quot; );         
</ins><span class="cx">                 }
</span><span class="cx">                 
</span><span class="cx">                 return $wpdb-&gt;get_results($sql);
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (1705 => 1706)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2009-08-26 16:21:57 UTC (rev 1705)
+++ trunk/bp-groups.php        2009-08-26 17:25:17 UTC (rev 1706)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> &lt;?php
</span><span class="cx"> 
</span><del>-define ( 'BP_GROUPS_DB_VERSION', '1700' );
</del><ins>+define ( 'BP_GROUPS_DB_VERSION', '1705' );
</ins><span class="cx"> 
</span><span class="cx"> /* Define the slug for the component */
</span><span class="cx"> if ( !defined( 'BP_GROUPS_SLUG' ) )
</span><span class="lines">@@ -69,6 +69,22 @@
</span><span class="cx">         require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
</span><span class="cx">         dbDelta($sql);
</span><span class="cx">         
</span><ins>+        /* On upgrade, handle moving of old group avatars */
+        $groups = groups_get_all();
+        
+        foreach ( $groups as $group ) {
+                /* Don't fetch and move gravs */
+                if ( strpos( $group-&gt;avatar_thumb, 'gravatar.com' ) )
+                        continue;
+
+                $upload_dir = groups_avatar_upload_dir( $group-&gt;id );
+                $avatar_thumb = str_replace( $bp-&gt;root_domain . '/' . basename( WP_CONTENT_DIR ), WP_CONTENT_PATH, $group-&gt;avatar_thumb );
+                $avatar_full = str_replace( $bp-&gt;root_domain . '/' . basename( WP_CONTENT_DIR ), WP_CONTENT_PATH, $group-&gt;avatar_full );
+
+                copy( $avatar_thumb, $upload_dir['path'] . basename($avatar_thumb) );
+                copy( $avatar_full, $upload_dir['path'] . basename($avatar_full) );
+        }
+        
</ins><span class="cx">         if ( function_exists('bp_wire_install') )
</span><span class="cx">                 groups_wire_install();
</span><span class="cx">         
</span><span class="lines">@@ -1501,8 +1517,6 @@
</span><span class="cx">          *        'status'
</span><span class="cx">          *        'enable_wire'
</span><span class="cx">          *        'enable_forum'
</span><del>-         *        'avatar_thumb'
-         *        'avatar_full'
</del><span class="cx">          *        'date_created'
</span><span class="cx">          */
</span><span class="cx"> 
</span><span class="lines">@@ -1544,12 +1558,6 @@
</span><span class="cx">         else if ( !$group_id &amp;&amp; !isset( $enable_forum ) )
</span><span class="cx">                 $group-&gt;enable_forum = 1;
</span><span class="cx">                         
</span><del>-        if ( isset( $avatar_thumb ) )
-                $group-&gt;avatar_thumb = $avatar_thumb;
-        
-        if ( isset( $avatar_full ) )
-                $group-&gt;avatar_full = $avatar_full;
-        
</del><span class="cx">         if ( isset( $date_created ) )
</span><span class="cx">                 $group-&gt;date_created = $date_created;
</span><span class="cx">         
</span><span class="lines">@@ -1783,7 +1791,7 @@
</span><span class="cx">         return BP_Groups_Group::get_popular( $limit, $page );
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-function groups_get_all( $limit = null, $page = 1, $only_public = true, $sort_by = false, $order = false ) {
</del><ins>+function groups_get_all( $limit = null, $page = 1, $only_public = false, $sort_by = false, $order = false ) {
</ins><span class="cx">         return BP_Groups_Group::get_all( $limit, $page, $only_public, $sort_by, $order );
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1881,21 +1889,24 @@
</span><span class="cx"> 
</span><span class="cx"> /*** Group Avatars *************************************************************/
</span><span class="cx"> 
</span><del>-function groups_avatar_upload_dir() {
</del><ins>+function groups_avatar_upload_dir( $group_id = false ) {
</ins><span class="cx">         global $bp;
</span><span class="cx"> 
</span><ins>+        if ( !$group_id )
+                $group_id = $bp-&gt;groups-&gt;current_group-&gt;id;
+                
</ins><span class="cx">         $path  = get_blog_option( BP_ROOT_BLOG, 'upload_path' );
</span><span class="cx">         $newdir = path_join( ABSPATH, $path );
</span><del>-        $newdir .= '/group-avatars/' . $bp-&gt;groups-&gt;current_group-&gt;id;
</del><ins>+        $newdir .= '/group-avatars/' . $group_id;
</ins><span class="cx"> 
</span><span class="cx">         $newbdir = $newdir;
</span><span class="cx">         
</span><span class="cx">         if ( !file_exists( $newdir ) )
</span><span class="cx">                 @wp_mkdir_p( $newdir );
</span><span class="cx"> 
</span><del>-        $newurl = WP_CONTENT_URL . '/blogs.dir/' . BP_ROOT_BLOG . '/files/group-avatars/' . $user_id;
</del><ins>+        $newurl = WP_CONTENT_URL . '/blogs.dir/' . BP_ROOT_BLOG . '/files/group-avatars/' . $group_id;
</ins><span class="cx">         $newburl = $newurl;
</span><del>-        $newsubdir = '/group-avatars/' . $bp-&gt;groups-&gt;current_group-&gt;id;
</del><ins>+        $newsubdir = '/group-avatars/' . $group_id;
</ins><span class="cx"> 
</span><span class="cx">         return apply_filters( 'groups_avatar_upload_dir', array( 'path' =&gt; $newdir, 'url' =&gt; $newurl, 'subdir' =&gt; $newsubdir, 'basedir' =&gt; $newbdir, 'baseurl' =&gt; $newburl, 'error' =&gt; false ) );        
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>