]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '1.0.x' into schema-x
authorBrion Vibber <brion@pobox.com>
Fri, 15 Oct 2010 18:40:40 +0000 (11:40 -0700)
committerBrion Vibber <brion@pobox.com>
Fri, 15 Oct 2010 18:40:40 +0000 (11:40 -0700)
1  2 
plugins/OStatus/classes/Ostatus_profile.php

index a43e3e708d8ede32b8c86d92ffe9476160f48599,03fcb71df02a16b79d7f9be365dabd476c2718e8..572b5ea0718336b79dfbff9eb6b42c16ebb8588e
@@@ -25,8 -25,7 +25,8 @@@ if (!defined('STATUSNET')) 
   * @package OStatusPlugin
   * @maintainer Brion Vibber <brion@status.net>
   */
 -class Ostatus_profile extends Memcached_DataObject
 +
 +class Ostatus_profile extends Managed_DataObject
  {
      public $__table = 'ostatus_profile';
  
      }
  
      /**
 -     * return table definition for DB_DataObject
 -     *
 -     * DB_DataObject needs to know something about the table to manipulate
 -     * instances. This method provides all the DB_DataObject needs to know.
 +     * Return table definition for Schema setup and DB_DataObject usage.
       *
       * @return array array of column definitions
       */
 -    function table()
 -    {
 -        return array('uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
 -                     'profile_id' => DB_DATAOBJECT_INT,
 -                     'group_id' => DB_DATAOBJECT_INT,
 -                     'feeduri' => DB_DATAOBJECT_STR,
 -                     'salmonuri' =>  DB_DATAOBJECT_STR,
 -                     'avatar' =>  DB_DATAOBJECT_STR,
 -                     'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
 -                     'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
 -    }
  
      static function schemaDef()
      {
 -        return array(new ColumnDef('uri', 'varchar',
 -                                   255, false, 'PRI'),
 -                     new ColumnDef('profile_id', 'integer',
 -                                   null, true, 'UNI'),
 -                     new ColumnDef('group_id', 'integer',
 -                                   null, true, 'UNI'),
 -                     new ColumnDef('feeduri', 'varchar',
 -                                   255, true, 'UNI'),
 -                     new ColumnDef('salmonuri', 'text',
 -                                   null, true),
 -                     new ColumnDef('avatar', 'text',
 -                                   null, true),
 -                     new ColumnDef('created', 'datetime',
 -                                   null, false),
 -                     new ColumnDef('modified', 'datetime',
 -                                   null, false));
 -    }
 -
 -    /**
 -     * return key definitions for DB_DataObject
 -     *
 -     * DB_DataObject needs to know about keys that the table has; this function
 -     * defines them.
 -     *
 -     * @return array key definitions
 -     */
 -    function keys()
 -    {
 -        return array_keys($this->keyTypes());
 -    }
 -
 -    /**
 -     * return key definitions for Memcached_DataObject
 -     *
 -     * Our caching system uses the same key definitions, but uses a different
 -     * method to get them.
 -     *
 -     * @return array key definitions
 -     */
 -    function keyTypes()
 -    {
 -        return array('uri' => 'K', 'profile_id' => 'U', 'group_id' => 'U', 'feeduri' => 'U');
 -    }
 -
 -    function sequenceKey()
 -    {
 -        return array(false, false, false);
 +        return array(
 +            'fields' => array(
 +                'uri' => array('type' => 'varchar', 'length' => 255, 'not null' => true),
 +                'profile_id' => array('type' => 'integer'),
 +                'group_id' => array('type' => 'integer'),
 +                'feeduri' => array('type' => 'varchar', 'length' => 255),
 +                'salmonuri' => array('type' => 'varchar', 'length' => 255),
 +                'avatar' => array('type' => 'text'),
 +                'created' => array('type' => 'datetime', 'not null' => true),
 +                'modified' => array('type' => 'datetime', 'not null' => true),
 +            ),
 +            'primary key' => array('uri'),
 +            'unique keys' => array(
 +                'ostatus_profile_profile_id_idx' => array('profile_id'),
 +                'ostatus_profile_group_id_idx' => array('group_id'),
 +                'ostatus_profile_feeduri_idx' => array('feeduri'),
 +            ),
 +            'foreign keys' => array(
 +                'profile_id' => array('profile' => 'id'),
 +                'group_id' => array('user_group' => 'id'),
 +            ),
 +        );
      }
  
      /**
          // @fixme this should be better encapsulated
          // ripped from oauthstore.php (for old OMB client)
          $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
-         if (!copy($url, $temp_filename)) {
-             throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
-         }
+         try {
+             if (!copy($url, $temp_filename)) {
+                 throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
+             }
  
-         if ($this->isGroup()) {
-             $id = $this->group_id;
-         } else {
-             $id = $this->profile_id;
+             if ($this->isGroup()) {
+                 $id = $this->group_id;
+             } else {
+                 $id = $this->profile_id;
+             }
+             // @fixme should we be using different ids?
+             $imagefile = new ImageFile($id, $temp_filename);
+             $filename = Avatar::filename($id,
+                                          image_type_to_extension($imagefile->type),
+                                          null,
+                                          common_timestamp());
+             rename($temp_filename, Avatar::path($filename));
+         } catch (Exception $e) {
+             unlink($temp_filename);
+             throw $e;
          }
-         // @fixme should we be using different ids?
-         $imagefile = new ImageFile($id, $temp_filename);
-         $filename = Avatar::filename($id,
-                                      image_type_to_extension($imagefile->type),
-                                      null,
-                                      common_timestamp());
-         rename($temp_filename, Avatar::path($filename));
          // @fixme hardcoded chmod is lame, but seems to be necessary to
          // keep from accidentally saving images from command-line (queues)
          // that can't be read from web server, which causes hard-to-notice