From f57514606a43edf87124a1c4576f86bd5a79094a Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Thu, 2 Dec 2010 14:39:18 +0100 Subject: [PATCH] Stores all account modification for active profiles in order to let the secretaries check them and to notify their owner. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- bin/cron/profile_modification.php | 6 ++++-- modules/profile/page.inc.php | 26 ++++++++++++++------------ upgrade/1.0.2/02_modifications.sql | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 upgrade/1.0.2/02_modifications.sql diff --git a/bin/cron/profile_modification.php b/bin/cron/profile_modification.php index 8d4b4d0..252e392 100755 --- a/bin/cron/profile_modification.php +++ b/bin/cron/profile_modification.php @@ -31,7 +31,8 @@ $res = XDB::iterator('SELECT p.hrpid, pm.pid, a.full_name, pm.field, pm.oldText INNER JOIN profile_display AS pd ON (pm.pid = pd.pid) INNER JOIN account_profiles AS ap ON (pm.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms)) INNER JOIN aliases AS al ON (ap.uid = al.uid AND FIND_IN_SET(\'bestalias\', al.flags)) - ORDER BY pm.pid, pm.field'); + WHERE pm.type = \'third_party\' + ORDER BY pm.pid, pm.field, pm.timestamp'); if ($res->total() > 0) { $date = time(); @@ -83,7 +84,8 @@ if ($res->total() > 0) { $mailer->assign('date', $date); $mailer->send(); - XDB::execute('DELETE FROM profile_modifications'); + XDB::execute('DELETE FROM profile_modifications + WHERE type = \'third_party\''); } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index 651bb38..53ffa0e 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -270,13 +270,13 @@ abstract class ProfilePage implements PlWizardPage if ($this->changed[$field]) { if (!is_null($setting)) { $changedFields[$field] = array( - str_replace("\n", " - ", $setting->getText($this->orig[$field])), - str_replace("\n", " - ", $setting->getText($this->values[$field])), + preg_replace('/(\r\n|\n|\r)/', ' - ', $setting->getText($this->orig[$field])), + preg_replace('/(\r\n|\n|\r)/', ' - ', $setting->getText($this->values[$field])), ); } else { $changedFields[$field] = array( - str_replace("\n", " - ", $this->orig[$field]), - str_replace("\n", " - ", $this->values[$field]), + preg_replace('/(\r\n|\n|\r)/', ' - ', $this->orig[$field]), + preg_replace('/(\r\n|\n|\r)/', ' - ', $this->values[$field]), ); } if (!is_null($setting)) { @@ -296,18 +296,20 @@ abstract class ProfilePage implements PlWizardPage global $platal; S::logger()->log('profil', $platal->pl_self(2)); - /** If the update was made by a third party and the profile corresponds - * to a registered user, stores both former and new text. - * This will be daily sent to the user. + /** Stores all profile modifications for active users in order to: + * -daily notify the user in case of third party edition, + * -display the modification to the secretaries for verification in + * case of an edition made by the user. */ $owner = $this->profile->owner(); $user = S::user(); - if ($owner->isActive() && $owner->id() != $user->id()) { + if ($owner->isActive()) { foreach ($changedFields as $field => $values) { - XDB::execute('INSERT INTO profile_modifications (pid, uid, field, oldText, newText) - VALUES ({?}, {?}, {?}, {?}, {?}) - ON DUPLICATE KEY UPDATE oldText = VALUES(oldText), newText = VALUES(newText)', - $this->pid(), $user->id(), $field, $values[0], $values[1]); + XDB::execute('INSERT INTO profile_modifications (pid, uid, field, oldText, newText, type, timestamp) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW()) + ON DUPLICATE KEY UPDATE uid = VALUES(uid), oldText = IF(VALUES(type) != type, VALUES(oldText), oldText), + newText = VALUES(newText), type = VALUES(type), timestamp = NOW()', + $this->pid(), $user->id(), $field, $values[0], $values[1], ($owner->id() == $user->id()) ? 'self' : 'third_party'); } } return true; diff --git a/upgrade/1.0.2/02_modifications.sql b/upgrade/1.0.2/02_modifications.sql new file mode 100644 index 0000000..f4965a7 --- /dev/null +++ b/upgrade/1.0.2/02_modifications.sql @@ -0,0 +1,23 @@ +DROP TABLE IF EXISTS tmp_profile_modifications; +CREATE TEMPORARY TABLE tmp_profile_modifications LIKE profile_modifications; +INSERT INTO tmp_profile_modifications SELECT * FROM profile_modifications; +DROP TABLE profile_modifications; +CREATE TABLE profile_modifications ( + pid INT(11) UNSIGNED NOT NULL DEFAULT 0, + uid INT(11) UNSIGNED NOT NULL DEFAULT 0, + field VARCHAR(60) NOT NULL, + oldText TEXT NOT NULL, + newText TEXT NOT NULL, + type ENUM('self', 'third_party') NOT NULL DEFAULT 'self', + timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (pid, field), + KEY uid (uid), + FOREIGN KEY (uid) REFERENCES accounts (uid) ON DELETE CASCADE ON UPDATE CASCADE, + FOREIGN KEY (pid) REFERENCES profiles (pid) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +INSERT INTO profile_modifications (pid, uid, field, oldText, newText, type) + SELECT pid, uid, field, oldText, newText, 'third_party' + FROM tmp_profile_modifications; +DROP TABLE IF EXISTS tmp_profile_modifications; + +-- vim:set syntax=mysql: -- 2.1.4