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();
$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:
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)) {
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;
--- /dev/null
+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: