From 2f0fe8e33ae29557911a0d1896a2c1b9725b5e55 Mon Sep 17 00:00:00 2001
From: Evan Prodromou <evan@controlyourself.ca>
Date: Fri, 22 May 2009 20:54:07 -0400
Subject: add design table to DB

---
 db/laconica.sql | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'db/laconica.sql')

diff --git a/db/laconica.sql b/db/laconica.sql
index 0b20bc172..d42c20e2a 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -482,3 +482,13 @@ create table file_to_post (
 
     unique(file_id, post_id)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
+
+create table design (
+    id integer primary key auto_increment comment 'design ID',
+    backgroundcolor integer comment 'main background color',
+    contentcolor integer comment 'content area background color',
+    sidebarcolor integer comment 'sidebar background color',
+    textcolor integer comment 'text color',
+    linkcolor integer comment 'link color',
+    backgroundimage varchar(255) comment 'background image, if any'
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
-- 
cgit v1.2.3-54-g00ecf


From 78564c21d46d56a2cf413b9ba804d5a60430f06e Mon Sep 17 00:00:00 2001
From: Evan Prodromou <evan@controlyourself.ca>
Date: Fri, 22 May 2009 23:43:38 -0400
Subject: schema changes for user support of designs

---
 db/laconica.sql | 3 +++
 1 file changed, 3 insertions(+)

(limited to 'db/laconica.sql')

diff --git a/db/laconica.sql b/db/laconica.sql
index d42c20e2a..c87340e8e 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -41,6 +41,7 @@ create table sms_carrier (
 /* local users */
 
 create table user (
+
     id integer primary key comment 'foreign key to profile table' references profile (id),
     nickname varchar(64) unique key comment 'nickname or username, duped in profile',
     password varchar(255) comment 'salted password, can be null for OpenID users',
@@ -71,6 +72,8 @@ create table user (
     inboxed tinyint default 0 comment 'has an inbox been created for this user?',
     created datetime not null comment 'date this record was created',
     modified timestamp comment 'date this record was modified',
+    design_id integer comment 'id of a design' references design(id),
+    viewdesigns tinyint default 1 comment 'whether to view user-provided designs',
 
     index user_smsemail_idx (smsemail)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
-- 
cgit v1.2.3-54-g00ecf


From b0e92c75cc19a91e1ea4bbb8009f6f66dc56231b Mon Sep 17 00:00:00 2001
From: Evan Prodromou <evan@controlyourself.ca>
Date: Sat, 23 May 2009 23:16:52 -0400
Subject: move design items before timestamps

---
 db/laconica.sql | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

(limited to 'db/laconica.sql')

diff --git a/db/laconica.sql b/db/laconica.sql
index c87340e8e..2ad482aba 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -70,11 +70,12 @@ create table user (
     autosubscribe tinyint default 0 comment 'automatically subscribe to users who subscribe to us',
     urlshorteningservice varchar(50) default 'ur1.ca' comment 'service to use for auto-shortening URLs',
     inboxed tinyint default 0 comment 'has an inbox been created for this user?',
-    created datetime not null comment 'date this record was created',
-    modified timestamp comment 'date this record was modified',
     design_id integer comment 'id of a design' references design(id),
     viewdesigns tinyint default 1 comment 'whether to view user-provided designs',
 
+    created datetime not null comment 'date this record was created',
+    modified timestamp comment 'date this record was modified',
+
     index user_smsemail_idx (smsemail)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
 
-- 
cgit v1.2.3-54-g00ecf


From 754b610ac4e4478cd36e5826f6bbfcad0531b7aa Mon Sep 17 00:00:00 2001
From: Evan Prodromou <evan@controlyourself.ca>
Date: Sun, 14 Jun 2009 12:04:45 -0700
Subject: added group_block table to database

---
 db/laconica.sql | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'db/laconica.sql')

diff --git a/db/laconica.sql b/db/laconica.sql
index a11e31692..3ffe1ed81 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -482,3 +482,13 @@ create table file_to_post (
 
     unique(file_id, post_id)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
+
+create table group_block (
+   group_id integer not null comment 'group profile is blocked from' references user_group (id),
+   blocked integer not null comment 'profile that is blocked' references profile (id),
+   blocker integer not null comment 'user making the block' references user (id),
+   modified timestamp comment 'date of blocking',
+
+   constraint primary key (group_id, blocked)
+
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
-- 
cgit v1.2.3-54-g00ecf


From 21e89d6f724fe8d54788a73b4b8325fdef647af3 Mon Sep 17 00:00:00 2001
From: Robin Millette <millette@controlyourself.ca>
Date: Sun, 14 Jun 2009 16:06:52 -0400
Subject: Commented all .sql fields for file/url related tables.

---
 db/laconica.sql | 55 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 27 deletions(-)

(limited to 'db/laconica.sql')

diff --git a/db/laconica.sql b/db/laconica.sql
index a11e31692..7f52a5ef7 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -427,49 +427,50 @@ create table group_inbox (
 
 create table file (
     id integer primary key auto_increment,
-    url varchar(255), mimetype varchar(50),
-    size integer,
-    title varchar(255),
-    date integer(11),
-    protected integer(1),
+    url varchar(255) comment 'destination URL after following redirections',
+    mimetype varchar(50) comment 'mime type of resource',
+    size integer comment 'size of resource when available',
+    title varchar(255) comment 'title of resource when available',
+    date integer(11) comment 'date of resource according to http query',
+    protected integer(1) comment 'true when URL is private (needs login)',
 
     unique(url)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
 
 create table file_oembed (
     id integer primary key auto_increment,
-    file_id integer,
-    version varchar(20),
-    type varchar(20),
-    provider varchar(50),
-    provider_url varchar(255),
-    width integer,
-    height integer,
-    html text,
-    title varchar(255),
-    author_name varchar(50),
-    author_url varchar(255),
-    url varchar(255),
+    file_id integer comment 'oEmbed for that URL/file' references file (id),
+    version varchar(20) comment 'oEmbed spec. version',
+    type varchar(20) comment 'oEmbed type: photo, video, link, rich',
+    provider varchar(50) comment 'name of this oEmbed provider',
+    provider_url varchar(255) comment 'URL of this oEmbed provider',
+    width integer comment 'width of oEmbed resource when available',
+    height integer comment 'height of oEmbed resource when available',
+    html text comment 'html representation of this oEmbed resource when applicable',
+    title varchar(255) comment 'title of oEmbed resource when available',
+    author_name varchar(50) comment 'author name for this oEmbed resource',
+    author_url varchar(255) comment 'author URL for this oEmbed resource',
+    url varchar(255) comment 'URL for this oEmbed resource when applicable (photo, link)',
 
     unique(file_id)
 ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
 
 create table file_redirection (
     id integer primary key auto_increment,
-    url varchar(255),
-    file_id integer,
-    redirections integer,
-    httpcode integer,
+    url varchar(255) comment 'short URL (or any other kind of redirect) for file (id)',
+    file_id integer comment 'short URL for what URL/file' references file (id),
+    redirections integer comment 'redirect count',
+    httpcode integer comment 'HTTP status code (20x, 30x, etc.)',
 
     unique(url)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
 create table file_thumbnail (
     id integer primary key auto_increment,
-    file_id integer,
-    url varchar(255),
-    width integer,
-    height integer,
+    file_id integer comment 'thumbnail for what URL/file' references file (id),
+    url varchar(255) comment 'URL of thumbnail',
+    width integer comment 'width of thumbnail',
+    height integer comment 'height of thumbnail',
 
     unique(file_id),
     unique(url)
@@ -477,8 +478,8 @@ create table file_thumbnail (
 
 create table file_to_post (
     id integer primary key auto_increment,
-    file_id integer,
-    post_id integer,
+    file_id integer comment 'id of URL/file' references file (id),
+    post_id integer comment 'id of the notice it belongs to' references notice (id),
 
     unique(file_id, post_id)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
-- 
cgit v1.2.3-54-g00ecf


From 0deb2928e649c358ce1046028dcca4dabc4b3aa6 Mon Sep 17 00:00:00 2001
From: Evan Prodromou <evan@controlyourself.ca>
Date: Sun, 14 Jun 2009 21:40:47 -0700
Subject: add a table for group aliases

---
 db/laconica.sql | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'db/laconica.sql')

diff --git a/db/laconica.sql b/db/laconica.sql
index bc824fc4d..b8c0824f5 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -493,3 +493,13 @@ create table group_block (
    constraint primary key (group_id, blocked)
 
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
+
+create table group_alias (
+
+   alias varchar(64) primary key comment 'additional nickname for the group',
+   group_id integer not null comment 'group profile is blocked from' references user_group (id),
+   modified timestamp comment 'date alias was created',
+
+   index group_alias_group_id_idx (group_id)
+
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
-- 
cgit v1.2.3-54-g00ecf


From 7b7f11942885666bfe1f03dd6f34e36a82a08484 Mon Sep 17 00:00:00 2001
From: Zach Copley <zach@controlyourself.ca>
Date: Tue, 16 Jun 2009 21:36:15 -0700
Subject: Added background image tile flag to Design

---
 classes/Design.php   | 19 ++++++++++---------
 classes/laconica.ini |  1 +
 db/laconica.sql      |  3 ++-
 3 files changed, 13 insertions(+), 10 deletions(-)

(limited to 'db/laconica.sql')

diff --git a/classes/Design.php b/classes/Design.php
index f5c87b489..acc94d196 100644
--- a/classes/Design.php
+++ b/classes/Design.php
@@ -41,6 +41,7 @@ class Design extends Memcached_DataObject
     public $textcolor;                       // int(4)
     public $linkcolor;                       // int(4)
     public $backgroundimage;                 // varchar(255)
+    public $tile;                            // tinyint(1)  
 
     /* Static get */
     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); }
@@ -63,23 +64,23 @@ class Design extends Memcached_DataObject
             common_log(LOG_ERR, "Unable to create color for design $id.",
                 __FILE__);
         }
-
+        
         $css  = 'html, body { background-color: #' . $bgcolor->hexValue() . '} ' . "\n";
         $css .= '#content, #site_nav_local_views .current a { background-color: #';
         $css .= $ccolor->hexValue() . '} '."\n";
         $css .= '#aside_primary { background-color: #'. $sbcolor->hexValue() . '} ' . "\n";
         $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n";
         $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n";
-
+        
         if (!empty($this->backgroundimage)) {
-
-            $css .= 'body { background-image:url(' .
-                Design::url($this->backgroundimage) .
+        
+            $css .= 'body { background-image:url(' . 
+                Design::url($this->backgroundimage) . 
                 '); background-repeat:no-repeat; }' . "\n";
         }
-
+        
         $out->element('style', array('type' => 'text/css'), $css);
-
+    
     }
 
     static function filename($id, $extension, $extra=null)
@@ -97,7 +98,7 @@ class Design extends Memcached_DataObject
 
         return $dir . $filename;
     }
-
+    
     static function url($filename)
     {
         $path = common_config('background', 'path');
@@ -120,5 +121,5 @@ class Design extends Memcached_DataObject
 
         return 'http://'.$server.$path.$filename;
     }
-
+    
 }
diff --git a/classes/laconica.ini b/classes/laconica.ini
index c04ae758f..569681984 100755
--- a/classes/laconica.ini
+++ b/classes/laconica.ini
@@ -46,6 +46,7 @@ sidebarcolor = 1
 textcolor = 1
 linkcolor = 1
 backgroundimage = 2
+tile = 17
 
 [design__keys]
 id = N
diff --git a/db/laconica.sql b/db/laconica.sql
index bd95d1ade..1f302de16 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -495,7 +495,8 @@ create table design (
     sidebarcolor integer comment 'sidebar background color',
     textcolor integer comment 'text color',
     linkcolor integer comment 'link color',
-    backgroundimage varchar(255) comment 'background image, if any'
+    backgroundimage varchar(255) comment 'background image, if any',
+    tile tinyint default 0 comment 'tile background image'
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
 create table group_block (
-- 
cgit v1.2.3-54-g00ecf


From 76cbeff33c9659cacbb57943056aabcb1517ca5c Mon Sep 17 00:00:00 2001
From: Zach Copley <zach@controlyourself.ca>
Date: Wed, 17 Jun 2009 02:35:51 -0700
Subject: Update background image settings to use bitflags

---
 actions/designsettings.php | 100 +++++++++++++++++++++++++++------------------
 classes/Design.php         |  33 +++++++++++++--
 classes/laconica.ini       |   2 +-
 db/laconica.sql            |   2 +-
 lib/common.php             |   2 +-
 5 files changed, 93 insertions(+), 46 deletions(-)

(limited to 'db/laconica.sql')

diff --git a/actions/designsettings.php b/actions/designsettings.php
index fbec3fc67..3dfaddd7b 100644
--- a/actions/designsettings.php
+++ b/actions/designsettings.php
@@ -104,37 +104,52 @@ class DesignsettingsAction extends AccountSettingsAction
                                       'value' => ImageFile::maxFileSizeInt()));
         $this->elementEnd('li');
 
-        $this->elementStart('li', array('id' => 'design_background-image_onoff'));
-
         if (!empty($design->backgroundimage)) {
+
+            $this->elementStart('li', array('id' => 'design_background-image_onoff'));
+
             $this->element('img', array('src' =>
                 Design::url($design->backgroundimage)));
-        }
 
-        $this->element('input', array('name' => 'design_background-image_onoff',
-                                      'type' => 'radio',
-                                      'id' => 'design_background-image_on',
-                                      'class' => 'radio',
-                                      'value' => 'true',
-                                      'checked'=> 'checked'));
-        $this->element('label', array('for' => 'design_background-image_on',
-                                      'class' => 'radio'),
-                                      _('On'));
-        $this->element('input', array('name' => 'design_background-image_onoff',
-                                      'type' => 'radio',
-                                      'id' => 'design_background-image_off',
-                                      'class' => 'radio',
-                                      'value' => 'false'));
-        $this->element('label', array('for' => 'design_background-image_off',
-                                      'class' => 'radio'),
-                                      _('Off'));
-        $this->element('p', 'form_guide', _('Turn background image on or off.'));
-        $this->elementEnd('li');
+            $attrs = array('name' => 'design_background-image_onoff',
+                           'type' => 'radio',
+                           'id' => 'design_background-image_on',
+                           'class' => 'radio',
+                           'value' => 'on');
+
+            if ($design->disposition & BACKGROUND_ON) {
+                $attrs['checked'] = 'checked';
+            }
+
+            $this->element('input', $attrs);
+
+            $this->element('label', array('for' => 'design_background-image_on',
+                                          'class' => 'radio'),
+                                          _('On'));
+
+            $attrs = array('name' => 'design_background-image_onoff',
+                           'type' => 'radio',
+                           'id' => 'design_background-image_off',
+                           'class' => 'radio',
+                           'value' => 'off');
+
+            if ($design->disposition & BACKGROUND_OFF) {
+                $attrs['checked'] = 'checked';
+            }
+
+            $this->element('input', $attrs);
+
+            $this->element('label', array('for' => 'design_background-image_off',
+                                          'class' => 'radio'),
+                                          _('Off'));
+            $this->element('p', 'form_guide', _('Turn background image on or off.'));
+            $this->elementEnd('li');
+        }
 
         $this->elementStart('li');
         $this->checkbox('design_background-image_repeat',
                         _('Tile background image'),
-                        $design->tile);
+                        ($design->disposition & BACKGROUND_TILE) ? true : false );
         $this->elementEnd('li');
 
         $this->elementEnd('ul');
@@ -159,7 +174,6 @@ class DesignsettingsAction extends AccountSettingsAction
                                           'value' => '#' . $bgcolor->hexValue()));
             $this->elementEnd('li');
 
-
             $ccolor = new WebColor($design->contentcolor);
 
             $this->elementStart('li');
@@ -346,7 +360,7 @@ class DesignsettingsAction extends AccountSettingsAction
 
             $design->backgroundimage = $defaults['backgroundimage'];
 
-            $deisng->tile = $defaults['tile'];
+            $deisng->disposition = $defaults['disposition'];
 
         } catch (WebColorException $e) {
             common_log(LOG_ERR, _('Bad default color settings: ' .
@@ -377,7 +391,23 @@ class DesignsettingsAction extends AccountSettingsAction
             return;
         }
 
-        $tile = $this->boolean('design_background-image_repeat');
+        $onoff = $this->arg('design_background-image_onoff');
+
+        $on   = false;
+        $off  = false;
+        $tile = false;
+
+        if ($onoff == 'on') {
+            $on = true;
+        } else {
+            $off = true;
+        }
+
+        $repeat = $this->boolean('design_background-image_repeat');
+
+        if ($repeat) {
+            $tile = true;
+        }
 
         $user = common_current_user();
         $design = $user->getDesign();
@@ -392,7 +422,8 @@ class DesignsettingsAction extends AccountSettingsAction
             $design->textcolor       = $tcolor->intValue();
             $design->linkcolor       = $lcolor->intValue();
             $design->backgroundimage = $filepath;
-            $design->tile            = $tile;
+
+            $design->setDisposition($on, $off, $tile);
 
             $result = $design->update($original);
 
@@ -416,7 +447,8 @@ class DesignsettingsAction extends AccountSettingsAction
             $design->textcolor       = $tcolor->intValue();
             $design->linkcolor       = $lcolor->intValue();
             $design->backgroundimage = $filepath;
-            $design->tile            = $tile;
+
+            $design->setDisposition($on, $off, $tile);
 
             $id = $design->insert();
 
@@ -481,16 +513,4 @@ class DesignsettingsAction extends AccountSettingsAction
         $this->showForm(_('Design preferences saved.'), true);
     }
 
-    /**
-     * Reset design settings to previous saved value if any, or
-     * the defaults
-     *
-     * @return void
-     */
-
-    function resetDesign()
-    {
-        $this->showForm(_('Design preferences reset.'), true);
-    }
-
 }
diff --git a/classes/Design.php b/classes/Design.php
index 4ea176677..5b28bf014 100644
--- a/classes/Design.php
+++ b/classes/Design.php
@@ -21,6 +21,10 @@ if (!defined('LACONICA')) {
     exit(1);
 }
 
+define('BACKGROUND_ON', 1);
+define('BACKGROUND_OFF', 2);
+define('BACKGROUND_TILE', 4);
+
 /**
  * Table Definition for design
  */
@@ -41,7 +45,7 @@ class Design extends Memcached_DataObject
     public $textcolor;                       // int(4)
     public $linkcolor;                       // int(4)
     public $backgroundimage;                 // varchar(255)
-    public $tile;                            // tinyint(1)
+    public $disposition;                     // tinyint(1)   default_1
 
     /* Static get */
     function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Design',$k,$v); }
@@ -72,9 +76,11 @@ class Design extends Memcached_DataObject
         $css .= 'html body { color: #'. $tcolor->hexValue() . '} '. "\n";
         $css .= 'a { color: #' . $lcolor->hexValue() . '} ' . "\n";
 
-        if (!empty($this->backgroundimage)) {
+        if (!empty($this->backgroundimage) &&
+            $this->disposition & BACKGROUND_ON) {
 
-           $repeat = ($this->tile) ? 'background-repeat:repeat;' :
+           $repeat = ($this->disposition & BACKGROUND_TILE) ?
+               'background-repeat:repeat;' :
                'background-repeat:no-repeat;';
 
             $css .= 'body { background-image:url(' .
@@ -125,4 +131,25 @@ class Design extends Memcached_DataObject
         return 'http://'.$server.$path.$filename;
     }
 
+    function setDisposition($on, $off, $tile)
+    {
+        if ($on) {
+            $this->disposition |= BACKGROUND_ON;
+        } else {
+            $this->disposition &= ~BACKGROUND_ON;
+        }
+
+        if ($off) {
+            $this->disposition |= BACKGROUND_OFF;
+        } else {
+            $this->disposition &= ~BACKGROUND_OFF;
+        }
+
+        if ($tile) {
+            $this->disposition |= BACKGROUND_TILE;
+        } else {
+            $this->disposition &= ~BACKGROUND_TILE;
+        }
+    }
+
 }
diff --git a/classes/laconica.ini b/classes/laconica.ini
index 569681984..1a650aba5 100755
--- a/classes/laconica.ini
+++ b/classes/laconica.ini
@@ -46,7 +46,7 @@ sidebarcolor = 1
 textcolor = 1
 linkcolor = 1
 backgroundimage = 2
-tile = 17
+disposition = 17
 
 [design__keys]
 id = N
diff --git a/db/laconica.sql b/db/laconica.sql
index 1f302de16..b018afec8 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -496,7 +496,7 @@ create table design (
     textcolor integer comment 'text color',
     linkcolor integer comment 'link color',
     backgroundimage varchar(255) comment 'background image, if any',
-    tile tinyint default 0 comment 'tile background image'
+    disposition tinyint default 1 comment 'bit 1 = hide background image, bit 2 = display background image, bit 4 = tile background image'
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
 create table group_block (
diff --git a/lib/common.php b/lib/common.php
index 629fee25b..bcf2e5d0c 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -79,7 +79,7 @@ $config =
                     'textcolor' => '#000000',
                     'linkcolor' => '#002E6E',
                     'backgroundimage' => null,
-                    'tile' => true),
+                    'disposition' => 1),
               'path' => $_path,
               'logfile' => null,
               'logo' => null,
-- 
cgit v1.2.3-54-g00ecf


From dff43c03e4cdd76419a430f0942e9eacf30e13b7 Mon Sep 17 00:00:00 2001
From: Zach Copley <zach@controlyourself.ca>
Date: Wed, 17 Jun 2009 22:16:09 -0700
Subject: Add design_id to User_group

---
 classes/User_group.php | 7 +++++++
 classes/laconica.ini   | 1 +
 db/laconica.sql        | 1 +
 3 files changed, 9 insertions(+)

(limited to 'db/laconica.sql')

diff --git a/classes/User_group.php b/classes/User_group.php
index 1a24124bb..8a56b9e52 100644
--- a/classes/User_group.php
+++ b/classes/User_group.php
@@ -19,6 +19,7 @@ class User_group extends Memcached_DataObject
     public $homepage_logo;                   // varchar(255)
     public $stream_logo;                     // varchar(255)
     public $mini_logo;                       // varchar(255)
+    public $design_id;                       // int(4)
     public $created;                         // datetime()   not_null
     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
@@ -239,4 +240,10 @@ class User_group extends Memcached_DataObject
         }
         return null;
     }
+
+    function getDesign()
+    {
+        return Design::staticGet('id', $this->design_id);
+    }
+
 }
diff --git a/classes/laconica.ini b/classes/laconica.ini
index 1a650aba5..5ced15885 100755
--- a/classes/laconica.ini
+++ b/classes/laconica.ini
@@ -468,6 +468,7 @@ original_logo = 2
 homepage_logo = 2
 stream_logo = 2
 mini_logo = 2
+design_id = 1
 created = 142
 modified = 384
 
diff --git a/db/laconica.sql b/db/laconica.sql
index b018afec8..8d1d47d38 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -387,6 +387,7 @@ create table user_group (
     homepage_logo varchar(255) comment 'homepage (profile) size logo',
     stream_logo varchar(255) comment 'stream-sized logo',
     mini_logo varchar(255) comment 'mini logo',
+    design_id integer comment 'id of a design' references design(id),
 
     created datetime not null comment 'date this record was created',
     modified timestamp comment 'date this record was modified',
-- 
cgit v1.2.3-54-g00ecf


From 05e51228020fecaa894523b5159bc412d48e5b19 Mon Sep 17 00:00:00 2001
From: Evan Prodromou <evan@controlyourself.ca>
Date: Mon, 22 Jun 2009 14:19:41 -0700
Subject: Database changes for file tables

Some minor database changes for file tables. Namely:

 * Added a timestamp to all tables
 * Added a filename column for local files
 * Change some tables that had unnecessary auto-increment primary
   keys when they had another unique column that should act as
   the primary key
 * Change engine from MyISAM to InnoDB for a couple of files.

Also, rebuilt the DB_DataObject files for all these tables.
---
 classes/File.php             | 10 ++++++----
 classes/File_oembed.php      | 10 +++++-----
 classes/File_redirection.php | 10 +++++-----
 classes/File_thumbnail.php   |  8 ++++----
 classes/File_to_post.php     |  6 +++---
 classes/laconica.ini         | 30 +++++++++++++++++-------------
 db/laconica.sql              | 31 ++++++++++++++++++-------------
 7 files changed, 58 insertions(+), 47 deletions(-)

(limited to 'db/laconica.sql')

diff --git a/classes/File.php b/classes/File.php
index 890536035..800041d5d 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -36,13 +36,15 @@ class File extends Memcached_DataObject
     /* the code below is auto generated do not remove the above tag */
 
     public $__table = 'file';                            // table name
-    public $id;                              // int(11)  not_null primary_key group_by
+    public $id;                              // int(4)  primary_key not_null
     public $url;                             // varchar(255)  unique_key
     public $mimetype;                        // varchar(50)  
-    public $size;                            // int(11)  group_by
+    public $size;                            // int(4)  
     public $title;                           // varchar(255)  
-    public $date;                            // int(11)  group_by
-    public $protected;                       // int(1)  group_by
+    public $date;                            // int(4)  
+    public $protected;                       // int(4)  
+    public $filename;                        // varchar(255)  
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
     /* Static get */
     function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File',$k,$v); }
diff --git a/classes/File_oembed.php b/classes/File_oembed.php
index 2e8e851cd..f9ca14e3c 100644
--- a/classes/File_oembed.php
+++ b/classes/File_oembed.php
@@ -31,19 +31,19 @@ class File_oembed extends Memcached_DataObject
     /* the code below is auto generated do not remove the above tag */
 
     public $__table = 'file_oembed';                     // table name
-    public $id;                              // int(11)  not_null primary_key group_by
-    public $file_id;                         // int(11)  unique_key group_by
+    public $file_id;                         // int(4)  primary_key not_null
     public $version;                         // varchar(20)  
     public $type;                            // varchar(20)  
     public $provider;                        // varchar(50)  
     public $provider_url;                    // varchar(255)  
-    public $width;                           // int(11)  group_by
-    public $height;                          // int(11)  group_by
-    public $html;                            // blob(65535)  blob
+    public $width;                           // int(4)  
+    public $height;                          // int(4)  
+    public $html;                            // text()  
     public $title;                           // varchar(255)  
     public $author_name;                     // varchar(50)  
     public $author_url;                      // varchar(255)  
     public $url;                             // varchar(255)  
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
     /* Static get */
     function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_oembed',$k,$v); }
diff --git a/classes/File_redirection.php b/classes/File_redirection.php
index 0d6e2a700..13f02f8e5 100644
--- a/classes/File_redirection.php
+++ b/classes/File_redirection.php
@@ -36,11 +36,11 @@ class File_redirection extends Memcached_DataObject
     /* the code below is auto generated do not remove the above tag */
 
     public $__table = 'file_redirection';                // table name
-    public $id;                              // int(11)  not_null primary_key group_by
-    public $url;                             // varchar(255)  unique_key
-    public $file_id;                         // int(11)  group_by
-    public $redirections;                    // int(11)  group_by
-    public $httpcode;                        // int(11)  group_by
+    public $url;                             // varchar(255)  primary_key not_null
+    public $file_id;                         // int(4)  
+    public $redirections;                    // int(4)  
+    public $httpcode;                        // int(4)  
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
     /* Static get */
     function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_redirection',$k,$v); }
diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php
index 2908549da..40d85b258 100644
--- a/classes/File_thumbnail.php
+++ b/classes/File_thumbnail.php
@@ -31,11 +31,11 @@ class File_thumbnail extends Memcached_DataObject
     /* the code below is auto generated do not remove the above tag */
 
     public $__table = 'file_thumbnail';                  // table name
-    public $id;                              // int(11)  not_null primary_key group_by
-    public $file_id;                         // int(11)  unique_key group_by
+    public $file_id;                         // int(4)  primary_key not_null
     public $url;                             // varchar(255)  unique_key
-    public $width;                           // int(11)  group_by
-    public $height;                          // int(11)  group_by
+    public $width;                           // int(4)  
+    public $height;                          // int(4)  
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
     /* Static get */
     function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_thumbnail',$k,$v); }
diff --git a/classes/File_to_post.php b/classes/File_to_post.php
index 9362faaae..bb5f4e6e4 100644
--- a/classes/File_to_post.php
+++ b/classes/File_to_post.php
@@ -31,9 +31,9 @@ class File_to_post extends Memcached_DataObject
     /* the code below is auto generated do not remove the above tag */
 
     public $__table = 'file_to_post';                    // table name
-    public $id;                              // int(11)  not_null primary_key group_by
-    public $file_id;                         // int(11)  multiple_key group_by
-    public $post_id;                         // int(11)  group_by
+    public $file_id;                         // int(4)  primary_key not_null
+    public $post_id;                         // int(4)  primary_key not_null
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 
     /* Static get */
     function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('File_to_post',$k,$v); }
diff --git a/classes/laconica.ini b/classes/laconica.ini
index 5ced15885..7e9b2b791 100755
--- a/classes/laconica.ini
+++ b/classes/laconica.ini
@@ -68,13 +68,14 @@ size = 1
 title = 2
 date = 1
 protected = 1
+filename = 2
+modified = 384
 
 [file__keys]
 id = N
 
 [file_oembed]
-id = 129
-file_id = 1
+file_id = 129
 version = 2
 type = 2
 provider = 2
@@ -86,37 +87,40 @@ title = 2
 author_name = 2
 author_url = 2
 url = 2
+modified = 384
 
 [file_oembed__keys]
-id = N
+file_id = K
 
 [file_redirection]
-id = 129
-url = 2
+url = 130
 file_id = 1
 redirections = 1
 httpcode = 1
+modified = 384
 
 [file_redirection__keys]
-id = N
+url = K
 
 [file_thumbnail]
-id = 129
-file_id = 1
+file_id = 129
 url = 2
 width = 1
 height = 1
+modified = 384
 
 [file_thumbnail__keys]
-id = N
+file_id = K
+url = U
 
 [file_to_post]
-id = 129
-file_id = 1
-post_id = 1
+file_id = 129
+post_id = 129
+modified = 384
 
 [file_to_post__keys]
-id = N
+file_id = K
+post_id = K
 
 [foreign_link]
 user_id = 129
diff --git a/db/laconica.sql b/db/laconica.sql
index 8d1d47d38..95796d5cc 100644
--- a/db/laconica.sql
+++ b/db/laconica.sql
@@ -431,6 +431,7 @@ create table group_inbox (
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
 create table file (
+
     id integer primary key auto_increment,
     url varchar(255) comment 'destination URL after following redirections',
     mimetype varchar(50) comment 'mime type of resource',
@@ -438,13 +439,15 @@ create table file (
     title varchar(255) comment 'title of resource when available',
     date integer(11) comment 'date of resource according to http query',
     protected integer(1) comment 'true when URL is private (needs login)',
+    filename varchar(255) comment 'if a local file, name of the file',
+
+    modified timestamp comment 'date this record was modified',
 
     unique(url)
-) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
 
 create table file_oembed (
-    id integer primary key auto_increment,
-    file_id integer comment 'oEmbed for that URL/file' references file (id),
+    file_id integer primary key comment 'oEmbed for that URL/file' references file (id),
     version varchar(20) comment 'oEmbed spec. version',
     type varchar(20) comment 'oEmbed type: photo, video, link, rich',
     provider varchar(50) comment 'name of this oEmbed provider',
@@ -456,37 +459,39 @@ create table file_oembed (
     author_name varchar(50) comment 'author name for this oEmbed resource',
     author_url varchar(255) comment 'author URL for this oEmbed resource',
     url varchar(255) comment 'URL for this oEmbed resource when applicable (photo, link)',
+    modified timestamp comment 'date this record was modified'
 
-    unique(file_id)
-) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci;
+) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
 
 create table file_redirection (
-    id integer primary key auto_increment,
-    url varchar(255) comment 'short URL (or any other kind of redirect) for file (id)',
+
+    url varchar(255) primary key comment 'short URL (or any other kind of redirect) for file (id)',
     file_id integer comment 'short URL for what URL/file' references file (id),
     redirections integer comment 'redirect count',
     httpcode integer comment 'HTTP status code (20x, 30x, etc.)',
+    modified timestamp comment 'date this record was modified'
 
-    unique(url)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
 create table file_thumbnail (
-    id integer primary key auto_increment,
-    file_id integer comment 'thumbnail for what URL/file' references file (id),
+
+    file_id integer primary key comment 'thumbnail for what URL/file' references file (id),
     url varchar(255) comment 'URL of thumbnail',
     width integer comment 'width of thumbnail',
     height integer comment 'height of thumbnail',
+    modified timestamp comment 'date this record was modified',
 
-    unique(file_id),
     unique(url)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
 create table file_to_post (
-    id integer primary key auto_increment,
+
     file_id integer comment 'id of URL/file' references file (id),
     post_id integer comment 'id of the notice it belongs to' references notice (id),
+    modified timestamp comment 'date this record was modified',
+
+    constraint primary key (file_id, post_id)
 
-    unique(file_id, post_id)
 ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
 
 create table design (
-- 
cgit v1.2.3-54-g00ecf

