From 5c4ea53f1c66590a34fc10ae5767469c58b90a24 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Tue, 16 Feb 2010 22:30:44 +0100 Subject: [PATCH] Move table photo into profile_photos, rename uid to pid. Signed-off-by: Florent Bruneau --- classes/profile.php | 6 +++--- include/validations/photos.inc.php | 8 ++++---- modules/profile.php | 15 +++++++-------- modules/profile/general.inc.php | 8 ++++---- upgrade/account/09_photos.sql | 11 +++++++++++ 5 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 upgrade/account/09_photos.sql diff --git a/classes/profile.php b/classes/profile.php index d6694ba..ef87258 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -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 diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index a0a76c4..1aac216 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -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; } diff --git a/modules/profile.php b/modules/profile.php index 51bde1e..e397cff 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -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; } } diff --git a/modules/profile/general.inc.php b/modules/profile/general.inc.php index 8555a1f..5e70adc 100644 --- a/modules/profile/general.inc.php +++ b/modules/profile/general.inc.php @@ -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 index 0000000..b09a02f --- /dev/null +++ b/upgrade/account/09_photos.sql @@ -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: -- 2.1.4