Move table photo into profile_photos, rename uid to pid.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 16 Feb 2010 21:30:44 +0000 (22:30 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 16 Feb 2010 21:30:44 +0000 (22:30 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/profile.php
include/validations/photos.inc.php
modules/profile.php
modules/profile/general.inc.php
upgrade/account/09_photos.sql [new file with mode: 0644]

index d6694ba..ef87258 100644 (file)
@@ -228,9 +228,9 @@ class Profile
             $cond = ' AND pub IN ' . XDB::formatArray($this->visibility);
         }
         $res = XDB::query('SELECT  *
-                             FROM  photo
+                             FROM  profile_photos
                             WHERE  attachmime IN (\'jpeg\', \'png\')
-                                   ' . $cond . ' AND  uid = {?}',
+                                   ' . $cond . ' AND  pid = {?}',
                           $this->id());
         if ($res->numRows() > 0) {
             $photo = $res->fetchOneAssoc();
@@ -452,7 +452,7 @@ class Profile
                            LEFT JOIN  profile_name AS pn_n ON (pn_n.pid = p.pid
                                                                AND pn_n.typeid = ' . self::getNameTypeId('nickname', true) . ')
                            LEFT JOIN  profile_phones AS pp ON (pp.uid = p.pid AND pp.link_type = \'user\' AND tel_type = \'mobile\')
-                           LEFT JOIN  photo AS ph ON (ph.uid = p.pid)
+                           LEFT JOIN  profile_photos AS ph ON (ph.pid = p.pid)
                            LEFT JOIN  account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', ap.perms))
                                WHERE  p.pid IN ' . XDB::formatArray($pids) . '
                             GROUP BY  p.pid
index a0a76c4..1aac216 100644 (file)
@@ -137,11 +137,11 @@ class PhotoReq extends Validate
 
     public function commit()
     {
-        require_once 'notifs.inc.php';
-        XDB::execute('REPLACE INTO  photo (uid, attachmime, attach, x, y)
+        //require_once 'notifs.inc.php';
+        XDB::execute('REPLACE INTO  profile_photos (pid, attachmime, attach, x, y)
                             VALUES  ({?},{?},{?},{?},{?})',
-                     $this->user->id(), $this->mimetype, $this->data, $this->x, $this->y);
-        register_watch_op($this->user->id(), WATCH_FICHE, '', 'photo');
+                     $this->user->profile()->id(), $this->mimetype, $this->data, $this->x, $this->y);
+        //register_watch_op($this->user->id(), WATCH_FICHE, '', 'photo');
         return true;
     }
 
index 51bde1e..e397cff 100644 (file)
@@ -178,9 +178,9 @@ class ProfileModule extends PLModule
         } elseif (Env::v('suppr')) {
             S::assert_xsrf_token();
 
-            XDB::execute('DELETE FROM  photo
-                                WHERE  uid = {?}',
-                         S::v('uid'));
+            XDB::execute('DELETE FROM  profile_photos
+                                WHERE  pid = {?}',
+                         S::user()->profile()->id());
             XDB::execute('DELETE FROM  requests
                                 WHERE  user_id = {?} AND type="photo"',
                          S::v('uid'));
@@ -763,8 +763,7 @@ class ProfileModule extends PLModule
 
         switch ($action) {
             case "original":
-                pl_cached_content_headers("image/jpeg");
-               readfile("/home/web/trombino/photos" . $user->promo() . "/" . $user->login() . ".jpg");
+                PlImage::fromFile("/home/web/trombino/photos" . $user->promo() . "/" . $user->login() . ".jpg", "image/jpeg")->send();
                 exit;
 
             case "new":
@@ -775,14 +774,14 @@ class ProfileModule extends PLModule
                $mimetype = substr($_FILES['userfile']['type'], 6);
                unlink($_FILES['userfile']['tmp_name']);
                 XDB::execute(
-                        "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
-                        $user->id(), $mimetype, $data, $x, $y);
+                        "REPLACE INTO profile_photos SET pid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
+                        $user->profile()->id(), $mimetype, $data, $x, $y);
                break;
 
             case "delete":
                 S::assert_xsrf_token();
 
-                XDB::execute('DELETE FROM photo WHERE uid = {?}', $user->id());
+                XDB::execute('DELETE FROM profile_photos WHERE pid = {?}', $user->profile()->id());
                 break;
         }
     }
index 8555a1f..5e70adc 100644 (file)
@@ -406,8 +406,8 @@ class ProfileGeneral extends ProfilePage
 
         // Retreive photo informations
         $res = XDB::query("SELECT  pub
-                             FROM  photo
-                            WHERE  uid = {?}", $this->pid());
+                             FROM  profile_photos
+                            WHERE  pid = {?}", $this->pid());
         $this->values['photo_pub'] = $res->fetchOneCell();
 
         if ($this->owner) {
@@ -464,9 +464,9 @@ class ProfileGeneral extends ProfilePage
                          $this->pid(), $new_email);
         }
         if ($this->changed['photo_pub']) {
-            XDB::execute("UPDATE  photo
+            XDB::execute("UPDATE  profile_photos
                              SET  pub = {?}
-                           WHERE  uid = {?}",
+                           WHERE  pid = {?}",
                          $this->values['photo_pub'], $this->pid());
         }
         if ($this->changed['yourself']) {
diff --git a/upgrade/account/09_photos.sql b/upgrade/account/09_photos.sql
new file mode 100644 (file)
index 0000000..b09a02f
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE  profile_photos
+        LIKE  photo;
+ INSERT INTO  profile_photos
+      SELECT  *
+        FROM  photo;
+
+  ALTER TABLE  profile_photos
+CHANGE COLUMN  uid pid INT(6) not null;
+
+
+# vim:set ft=mysql: