From 00ba8a742be0cfc70eef7c6aaaccebe7134ec087 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Fri, 19 Nov 2010 13:33:07 +0100 Subject: [PATCH] REPLACE INTO should only be used if the data deletion is wanted. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- include/banana/forum.inc.php | 6 ++++-- include/emails.inc.php | 5 ++++- include/marketing.inc.php | 12 ++++++------ include/newsletter.inc.php | 34 +++++++++++++++++++--------------- include/notifs.inc.php | 5 +++-- include/reminder.inc.php | 6 +++--- include/reminder/promotion_ml.inc.php | 13 +++++-------- include/validations/homonymes.inc.php | 4 +++- include/validations/medals.inc.php | 5 +++-- include/validations/photos.inc.php | 6 ++++-- modules/admin.php | 9 +++++---- modules/axletter.php | 13 +++++++++---- modules/axletter/axletter.inc.php | 4 ++-- modules/carnet.php | 7 ++++--- modules/email.php | 5 +++-- modules/events.php | 12 +++++++----- modules/fusionax.php | 30 +++++++++++++++--------------- modules/platal.php | 5 +++-- modules/profile.php | 20 +++++++++++--------- modules/profile/jobs.inc.php | 11 +++++++---- modules/profile/mentor.inc.php | 5 +++-- modules/profile/page.inc.php | 5 +++-- modules/register.php | 21 +++++++++++---------- modules/register/register.inc.php | 13 ++++++------- modules/search.php | 7 ++++--- modules/xnetevents.php | 33 ++++++++++++--------------------- modules/xnetevents/xnetevents.inc.php | 4 ++-- modules/xnetgrp.php | 11 ++++++----- 28 files changed, 167 insertions(+), 144 deletions(-) diff --git a/include/banana/forum.inc.php b/include/banana/forum.inc.php index 5a665a6..b721d64 100644 --- a/include/banana/forum.inc.php +++ b/include/banana/forum.inc.php @@ -238,8 +238,10 @@ class ForumsBanana extends Banana } else { $last_seen = '0000-00-00'; } - XDB::execute('REPLACE INTO forum_profiles (uid, sig, mail, name, flags, tree_unread, tree_read, last_seen) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO forum_profiles (uid, sig, mail, name, flags, tree_unread, tree_read, last_seen) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE sig = VALUES(sig), mail = VALUES(mail), name = VALUES(name), flags = VALUES(flags), + tree_unread = VALUES(tree_unread), tree_read = VALUES(tree_read), last_seen = VALUES(last_seen)', $this->user->id(), Post::v('bananasig'), Post::v('bananamail'), Post::v('banananame'), $flags, $unread, $read, $last_seen); diff --git a/include/emails.inc.php b/include/emails.inc.php index 9b1f5a4..e29cf3e 100644 --- a/include/emails.inc.php +++ b/include/emails.inc.php @@ -555,7 +555,10 @@ class Redirect if (!isvalid_email_redirection($email_stripped)) { return ERROR_LOOP_EMAIL; } - XDB::execute('REPLACE INTO emails (uid,email,flags) VALUES({?},{?},"active")', $this->user->id(), $email); + // If the email was already present for this user, we reset it to the default values, we thus use REPLACE INTO. + XDB::execute('REPLACE INTO emails (uid, email, flags) + VALUES ({?}, {?}, \'active\')', + $this->user->id(), $email); if ($logger = S::v('log', null)) { // may be absent --> step4.php S::logger()->log('email_add', $email . ($this->user->id() != S::v('uid') ? " (admin on {$this->user->login()})" : "")); } diff --git a/include/marketing.inc.php b/include/marketing.inc.php index 18a3fe9..0155eee 100644 --- a/include/marketing.inc.php +++ b/include/marketing.inc.php @@ -329,9 +329,9 @@ class ListMarketing extends AnnuaireMarketing public function process(array $user) { - return XDB::execute("REPLACE INTO register_subs (uid, type, sub, domain) - VALUES ({?}, 'list', {?}, {?})", - $user['id'], $this->name, $this->domain); + return XDB::execute("INSERT IGNORE INTO register_subs (uid, type, sub, domain) + VALUES ({?}, 'list', {?}, {?})", + $user['id'], $this->name, $this->domain); } } @@ -359,9 +359,9 @@ class GroupMarketing extends AnnuaireMarketing public function process(array $user) { - return XDB::execute("REPLACE INTO register_subs (uid, type, sub, domain) - VALUES ({?}, 'group', {?}, '')", - $user['id'], $this->group); + return XDB::execute("INSERT IGNORE INTO register_subs (uid, type, sub, domain) + VALUES ({?}, 'group', {?}, '')", + $user['id'], $this->group); } } diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 86ce712..bccf89f 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -94,21 +94,25 @@ class NewsLetter extends MassMailer { $a->_cid = ($a->_cid == 0) ? null : $a->_cid; if ($a->_aid >= 0) { - XDB::execute('REPLACE INTO newsletter_art (id, aid, cid, pos, title, body, append) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', - $this->_id, $a->_aid, $a->_cid, $a->_pos, - $a->_title, $a->_body, $a->_append); - $this->_arts['a' . $a->_aid] = $a; + XDB::execute('UPDATE newsletter_art + SET cid = {?}, pos = {?}, title = {?}, body = {?}, append = {?} + WHERE id = {?} AND aid = {?}', + $a->_cid, $a->_pos, $a->_title, $a->_body, $a->_append, $this->_id, $a->_aid); } else { - XDB::execute('INSERT INTO newsletter_art - SELECT {?}, MAX(aid)+1, {?}, ' - . ($a->_pos ? intval($a->_pos) : 'MAX(pos)+1') - . ', {?}, {?}, {?} - FROM newsletter_art AS a - WHERE a.id = {?}', - $this->_id, $a->_cid, $a->_title, $a->_body, $a->_append, $this->_id); - $this->_arts['a' . $a->_aid] = $a; + XDB::startTransaction(); + list($aid, $pos) = XDB::fetchOneRow('SELECT MAX(aid) AS aid, MAX(pos) AS pos + FROM newsletter_art AS a + WHERE a.id = {?}', + $this->_id); + $a->_aid = ++$aid; + $a->_pos = ($a->_pos ? $a->_pos : ++$pos); + XDB::execute('INSERT INTO newsletter_art (id, aid, cid, pos, title, body, append) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', + $this->_id, $a->_aid, $a->_cid, $a->_pos, + $a->_title, $a->_body, $a->_append); + XDB::commit(); } + $this->_arts['a' . $a->_aid] = $a; } public function delArticle($aid) @@ -148,8 +152,8 @@ class NewsLetter extends MassMailer static public function subscribe($uid = null) { $user = is_null($uid) ? S::v('uid') : $uid; - XDB::execute("REPLACE INTO newsletter_ins (uid,last) - VALUES ({?}, NULL)", $user); + XDB::execute('INSERT IGNORE INTO newsletter_ins (uid, last, hash) + VALUES ({?}, NULL, NULL)', $user); } protected function subscriptionWhere() diff --git a/include/notifs.inc.php b/include/notifs.inc.php index 045adee..0d2c5e2 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -74,8 +74,9 @@ class WatchProfileUpdate extends WatchOperation public static function register(Profile &$profile, $field) { - XDB::execute('REPLACE INTO watch_profile (pid, ts, field) - VALUES ({?}, NOW(), {?})', + XDB::execute('INSERT INTO watch_profile (pid, ts, field) + VALUES ({?}, NOW(), {?}) + ON DUPLICATE KEY UPDATE ts = NOW()', $profile->id(), $field); } diff --git a/include/reminder.inc.php b/include/reminder.inc.php index 715d2d5..5201c8d 100644 --- a/include/reminder.inc.php +++ b/include/reminder.inc.php @@ -71,9 +71,9 @@ abstract class Reminder // and the next ask (if any). private static function UpdateStatus($uid, $type_id, $status, $next_ask) { - XDB::execute('REPLACE INTO reminder - SET uid = {?}, type_id = {?}, status = {?}, - remind_last = NOW(), remind_next = FROM_UNIXTIME({?})', + XDB::execute('INSERT INTO reminder (uid, type_id, status, remind_last, remind_next) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE status = VALUES(status), remind_last = NOW(), remind_next = VALUES(remind_next)', $uid, $type_id, $status, ($next_ask > 0 ? time() + $next_ask * 24 * 60 * 60 : null)); } diff --git a/include/reminder/promotion_ml.inc.php b/include/reminder/promotion_ml.inc.php index ffc33b2..1156e2a 100644 --- a/include/reminder/promotion_ml.inc.php +++ b/include/reminder/promotion_ml.inc.php @@ -26,14 +26,11 @@ class ReminderPromotionMl extends Reminder $user = S::user(); switch ($action) { case 'yes': - $res = XDB::query('SELECT id - FROM groups - WHERE diminutif = {?}', - $user->profile()->yearPromo()); - $asso_id = $res->fetchOneCell(); - XDB::execute('REPLACE INTO group_members (uid, asso_id) - VALUES ({?}, {?})', - $user->id(), $asso_id); + XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id) + SELECT {?}, id + FROM groups + WHERE diminutif = {?}' + $user->id(), $user->profile()->yearPromo()); $mmlist = new MMList($user); $mmlist->subscribe('promo' . $user->profile()->yearPromo()); diff --git a/include/validations/homonymes.inc.php b/include/validations/homonymes.inc.php index ec8e1fe..420fd65 100644 --- a/include/validations/homonymes.inc.php +++ b/include/validations/homonymes.inc.php @@ -124,7 +124,9 @@ est ambigu pour des raisons d'homonymie et signalera ton email exact."; switch_bestalias($this->user, $this->loginbis); if (!$this->warning) { XDB::execute("UPDATE aliases SET type = 'homonyme', expire = NOW() WHERE alias = {?}", $this->loginbis); - XDB::execute("REPLACE INTO homonyms (homonyme_id, uid) VALUES({?}, {?})", $this->user->id(), $this->user->id()); + XDB::execute('INSERT IGNORE INTO homonyms (homonyme_id, uid) + VALUES ({?}, {?})', + $this->user->id(), $this->user->id()); } return true; diff --git a/include/validations/medals.inc.php b/include/validations/medals.inc.php index df04da6..dbfbb4b 100644 --- a/include/validations/medals.inc.php +++ b/include/validations/medals.inc.php @@ -100,8 +100,9 @@ class MedalReq extends ProfileValidate public function commit () { - return XDB::execute('REPLACE INTO profile_medals - VALUES ({?}, {?}, {?})', + return XDB::execute('INSERT INTO profile_medals (pid, mid, gid) + VALUES ({?}, {?}, {?}) + ON DUPLICATE KEY UPDATE gid = VALUES(gid)', $this->profile->id(), $this->mid, is_null($this->gid) ? 0 : $this->gid); } diff --git a/include/validations/photos.inc.php b/include/validations/photos.inc.php index 60b6ae1..665c5d2 100644 --- a/include/validations/photos.inc.php +++ b/include/validations/photos.inc.php @@ -137,8 +137,10 @@ class PhotoReq extends ProfileValidate public function commit() { - XDB::execute('REPLACE INTO profile_photos (pid, attachmime, attach, x, y) - VALUES ({?},{?},{?},{?},{?})', + XDB::execute('INSERT INTO profile_photos (pid, attachmime, attach, x, y) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach) + x = VALUES(x), y = VALUES(y)', $this->profile->id(), $this->mimetype, $this->data, $this->x, $this->y); return true; diff --git a/modules/admin.php b/modules/admin.php index 223bc80..b2aeae9 100644 --- a/modules/admin.php +++ b/modules/admin.php @@ -973,8 +973,8 @@ class AdminModule extends PLModule XDB::execute("UPDATE aliases SET type = 'homonyme', expire=NOW() WHERE alias = {?}", $loginbis); - XDB::execute("REPLACE INTO homonyms (homonyme_id, uid) - VALUES ({?}, {?})", $target, $target); + XDB::execute('INSERT IGNORE INTO homonyms (homonyme_id, uid) + VALUES ({?}, {?})', $target, $target); send_robot_homonyme($user, $loginbis); $op = 'list'; $page->trigSuccess('Email envoyé à ' . $user->forlifeEmail() . ', alias supprimé.'); @@ -1110,8 +1110,9 @@ class AdminModule extends PLModule $hide[] = $cat; } $hide_requests = join(',', $hide); - XDB::query('REPLACE INTO requests_hidden (uid, hidden_requests) - VALUES ({?}, {?})', + XDB::query('INSERT INTO requests_hidden (uid, hidden_requests) + VALUES ({?}, {?}) + ON DUPLICATE KEY UPDATE hidden_requests = VALUES(hidden_requests)', S::v('uid'), $hide_requests); } elseif ($hide_requests) { foreach (explode(',', $hide_requests) as $hide_type) diff --git a/modules/axletter.php b/modules/axletter.php index d08b0bc..b0f654e 100644 --- a/modules/axletter.php +++ b/modules/axletter.php @@ -188,10 +188,15 @@ class AXLetterModule extends PLModule break; case 'Confirmer': - XDB::execute("REPLACE INTO axletter - SET id = {?}, short_name = {?}, subject = {?}, title = {?}, body = {?}, - signature = {?}, promo_min = {?}, promo_max = {?}, echeance = {?}, subset = {?}, subset_rm = {?}", - $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance, $subset ? implode("\n", $subset_to) : null, $subset_rm); + XDB::execute('INSERT INTO axletter (id, short_name, subject, title, body, signature, + promo_min, promo_max, echeance, subset, subset_rm) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE short_name = VALUES(short_name), subject = VALUES(subject), title = VALUES(title), + body = VALUES(body), signature = VALUES(signature), promo_min = VALUES(promo_min), + promo_max = VALUES(promo_max), echeance = VALUES(echeance), subset = VALUES(subset), + subset_rm = VALUES(subset_rm)', + $id, $short_name, $subject, $title, $body, $signature, $promo_min, $promo_max, $echeance, + $subset ? implode("\n", $subset_to) : null, $subset_rm); if (!$saved) { global $globals; $mailer = new PlMailer(); diff --git a/modules/axletter/axletter.inc.php b/modules/axletter/axletter.inc.php index 53c7dd3..8c28586 100644 --- a/modules/axletter/axletter.inc.php +++ b/modules/axletter/axletter.inc.php @@ -131,8 +131,8 @@ class AXLetter extends MassMailer static public function subscribe($uid = null) { $user = is_null($uid) ? S::v('uid') : $uid; - XDB::execute("REPLACE INTO axletter_ins (uid,last) - VALUES ({?}, 0)", $user); + XDB::execute('INSERT IGNORE INTO axletter_ins (uid, last) + VALUES ({?}, 0)', $user); } static public function hasPerms() diff --git a/modules/carnet.php b/modules/carnet.php index 33c750a..9454062 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -292,9 +292,10 @@ class CarnetModule extends PLModule case 'ajouter': if (($contact = User::get(Env::v('user')))) { - if (XDB::execute("REPLACE INTO contacts (uid, contact) - VALUES ({?}, {?})", - $uid, $contact->id())) { + XDB::execute('INSERT IGNORE INTO contacts (uid, contact) + VALUES ({?}, {?})', + $uid, $contact->id()); + if (XDB::affectedRows() > 0) { Platal::session()->updateNbNotifs(); $page->trigSuccess('Contact ajouté !'); } else { diff --git a/modules/email.php b/modules/email.php index 6f85504..a3f7b2b 100644 --- a/modules/email.php +++ b/modules/email.php @@ -385,8 +385,9 @@ class EmailModule extends PLModule $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']); $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']); $data = serialize($_POST); - XDB::execute("REPLACE INTO email_send_save - VALUES ({?}, {?})", + XDB::execute('INSERT INTO email_send_save (uid, data) + VALUES ({?}, {?}) + ON DUPLICATE KEY UPDATE data = VALUES(data)', S::user()->id('uid'), $data); } exit; diff --git a/modules/events.php b/modules/events.php index 4888268..9f434cb 100644 --- a/modules/events.php +++ b/modules/events.php @@ -144,8 +144,9 @@ class EventsModule extends PLModule FROM announce_read AS ev INNER JOIN announces AS e ON e.id = ev.evt_id WHERE expiration < NOW()'); - XDB::execute('REPLACE INTO announce_read VALUES({?},{?})', - $eid, S::v('uid')); + XDB::execute('INSERT IGNORE INTO announce_read (evt_id, uid) + VALUES ({?}, {?})', + $eid, S::v('uid')); pl_redirect('events#'.$pound); } @@ -382,9 +383,10 @@ class EventsModule extends PLModule Post::v('promo_min'), Post::v('promo_max'), $flags, $eid); if ($upload->exists() && list($x, $y, $type) = $upload->imageInfo()) { - XDB::execute('REPLACE INTO announce_photos - SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}', - $eid, $type, $x, $y, $upload->getContents()); + XDB::execute('INSERT INTO announce_photos (eid, attachmime, attach, x, y) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', + $eid, $type, $upload->getContents(), $x, $y); $upload->rm(); } } diff --git a/modules/fusionax.php b/modules/fusionax.php index 020eaee..1262db9 100644 --- a/modules/fusionax.php +++ b/modules/fusionax.php @@ -199,29 +199,29 @@ class FusionAxModule extends PLModule $directoryName = $lastname . ' ' . $firstname; ++$xorgId; - XDB::execute('REPLACE INTO profiles (hrpid, xorg_id, ax_id, sex) - VALUES ({?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO profiles (hrpid, xorg_id, ax_id, sex) + VALUES ({?}, {?}, {?}, {?})', $hrid, $xorgId, $ax_id, $sex); $pid = XDB::insertId(); - XDB::execute('REPLACE INTO profile_name (pid, name, typeid) - VALUES ({?}, {?}, {?})', + XDB::execute('INSERT INTO profile_name (pid, name, typeid) + VALUES ({?}, {?}, {?})', $pid, $lastname, $nameTypes['name_ini']); - XDB::execute('REPLACE INTO profile_name (pid, name, typeid) - VALUES ({?}, {?}, {?})', + XDB::execute('INSERT INTO profile_name (pid, name, typeid) + VALUES ({?}, {?}, {?})', $pid, $firstname, $nameTypes['firstname_ini']); - XDB::execute('REPLACE INTO profile_display (pid, yourself, public_name, private_name, - directory_name, short_name, sort_name, promo) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO profile_display (pid, yourself, public_name, private_name, + directory_name, short_name, sort_name, promo) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $pid, $firstname, $fullName, $fullName, $directoryName, $fullName, $directoryName, $promo); - XDB::execute('REPLACE INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags) - VALUES ({?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO profile_education (pid, eduid, degreeid, entry_year, grad_year, flags) + VALUES ({?}, {?}, {?}, {?}, {?}, {?})', $pid, $eduSchools[Profile::EDU_X], $degreeid, $entry_year, $grad_year, 'primary'); - XDB::execute('REPLACE INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO accounts (hruid, type, is_admin, state, full_name, directory_name, display_name, sex) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', $hrid, $type, 0, 'active', $fullName, $directoryName, $lastname, $sex); $uid = XDB::insertId(); - XDB::execute('REPLACE INTO account_profiles (uid, pid, perms) - VALUES ({?}, {?}, {?})', + XDB::execute('INSERT INTO account_profiles (uid, pid, perms) + VALUES ({?}, {?}, {?})', $uid, $pid, 'owner'); } $report[] = 'Promo 1920 ajoutée.'; diff --git a/modules/platal.php b/modules/platal.php index 7c3093b..cfa973f 100644 --- a/modules/platal.php +++ b/modules/platal.php @@ -156,8 +156,9 @@ class PlatalModule extends PLModule $page->trigError('URL invalide'); } else { $url = Env::t('url'); - XDB::execute('REPLACE INTO carvas (uid, url) - VALUES ({?}, {?})', + XDB::execute('INSERT INTO carvas (uid, url) + VALUES ({?}, {?}) + ON DUPLICATE KEY UPDATE url = VALUES(url)', S::i('uid'), $url); S::logger()->log('carva_add', 'http://' . $url); $page->trigSuccess("Redirection activée vers $url"); diff --git a/modules/profile.php b/modules/profile.php index be8648e..7392d5a 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -607,8 +607,9 @@ class ProfileModule extends PLModule } $res .= "\n"; } - XDB::query('REPLACE INTO search_autocomplete - VALUES ({?}, {?}, {?}, NOW())', + XDB::query('INSERT INTO search_autocomplete (name, query, result, generated) + VALUES ({?}, {?}, {?}, NOW()) + ON DUPLICATE KEY result = VALUES(result), generated = NOW()', $type, $q_normalized, $res); echo $res; exit(); @@ -687,13 +688,14 @@ class ProfileModule extends PLModule S::assert_xsrf_token(); $data = file_get_contents($_FILES['userfile']['tmp_name']); - list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']); - $mimetype = substr($_FILES['userfile']['type'], 6); - unlink($_FILES['userfile']['tmp_name']); - XDB::execute( - "REPLACE INTO profile_photos SET pid={?}, attachmime = {?}, attach={?}, x={?}, y={?}", - $user->profile()->id(), $mimetype, $data, $x, $y); - break; + list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']); + $mimetype = substr($_FILES['userfile']['type'], 6); + unlink($_FILES['userfile']['tmp_name']); + XDB::execute('INSERT INTO profile_photos (pid, attachmime, attach, x, y) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', + $user->profile()->id(), $mimetype, $data, $x, $y); + break; case "delete": S::assert_xsrf_token(); diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index eb7696b..760ab35 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -284,8 +284,9 @@ class ProfileSettingJob implements ProfileSetting } } if (count($terms_values) > 0) { - XDB::execute('REPLACE INTO profile_job_term (pid, jid, jtid, computed) - VALUES '.implode(', ', $terms_values)); + XDB::rawExecute('INSERT INTO profile_job_term (pid, jid, jtid, computed) + VALUES ' . implode(', ', $terms_values) . ' + ON DUPLICATE KEY UPDATE computed = VALUES(computed)'); } } @@ -323,8 +324,10 @@ class ProfileSettingCorps implements ProfileSetting public function save(ProfilePage &$page, $field, $value) { - XDB::execute('REPLACE INTO profile_corps (original_corpsid, current_corpsid, rankid, corps_pub, pid) - VALUES ({?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT INTO profile_corps (original_corpsid, current_corpsid, rankid, corps_pub, pid) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE original_corpsid = VALUES(original_corpsid), current_corpsid = VALUES(current_corpsid) + rankid = VALUES(rankid), corps_pub = VALUES(corps_pub)', $value['original'], $value['current'], $value['rank'], $value['pub'], $page->pid()); } diff --git a/modules/profile/mentor.inc.php b/modules/profile/mentor.inc.php index b34b6e8..14af014 100644 --- a/modules/profile/mentor.inc.php +++ b/modules/profile/mentor.inc.php @@ -164,8 +164,9 @@ class ProfilePageMentor extends ProfilePage $this->pid()); $this->values['expertise'] = null; } else { - XDB::execute("REPLACE INTO profile_mentor (pid, expertise) - VALUES ({?}, {?})", + XDB::execute('INSERT INTO profile_mentor (pid, expertise) + VALUES ({?}, {?}) + ON DUPLICATE KEY UPDATE expertise = VALUES(expertise)', $this->pid(), $expertise); $this->values['expertise'] = $expertise; } diff --git a/modules/profile/page.inc.php b/modules/profile/page.inc.php index d1a1cfc..ec70a0e 100644 --- a/modules/profile/page.inc.php +++ b/modules/profile/page.inc.php @@ -304,8 +304,9 @@ abstract class ProfilePage implements PlWizardPage $user = S::user(); if ($owner->isActive() && $owner->id() != $user->id()) { foreach ($changedFields as $field => $values) { - XDB::execute('REPLACE INTO profile_modifications (pid, uid, field, oldText, newText) - 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]); } } diff --git a/modules/register.php b/modules/register.php index 5df8c93..c53a456 100644 --- a/modules/register.php +++ b/modules/register.php @@ -67,10 +67,11 @@ class RegisterModule extends PLModule $subState->merge($res->fetchOneRow()); $subState->set('yearpromo', substr($subState->s('promo'), 1, 4)); - XDB::execute('REPLACE INTO register_mstats (uid,sender,success) - SELECT m.uid, m.sender, 0 - FROM register_marketing AS m - WHERE m.hash', + XDB::execute('INSERT INTO register_mstats (uid, sender, success) + SELECT m.uid, m.sender, 0 + FROM register_marketing AS m + WHERE m.hash + ON DUPLICATE KEY sender = VALUES(sender), success = VALUES(success)', $subState->s('hash')); } } @@ -368,8 +369,8 @@ class RegisterModule extends PLModule $r = XDB::query('SELECT id FROM groups WHERE diminutif = {?}', $yearpromo); if ($r->numRows()) { $asso_id = $r->fetchOneCell(); - XDB::execute('REPLACE INTO group_members (uid, asso_id) - VALUES ({?}, {?})', + XDB::execute('INSERT INTO group_members (uid, asso_id) + VALUES ({?}, {?})', $uid, $asso_id); $mmlist = new MMList($uid, S::v('password')); $mmlist->subscribe("promo" . S::v('promo')); @@ -398,10 +399,10 @@ class RegisterModule extends PLModule Profile::rebuildSearchTokens($pid); // Notify other users which were watching for her arrival. - XDB::execute('REPLACE INTO contacts (uid, contact) - SELECT uid, ni_id - FROM watch_nonins - WHERE ni_id = {?}', $uid); + XDB::execute('INSERT INTO contacts (uid, contact) + SELECT uid, ni_id + FROM watch_nonins + WHERE ni_id = {?}', $uid); XDB::execute('DELETE FROM watch_nonins WHERE ni_id = {?}', $uid); Platal::session()->updateNbNotifs(); diff --git a/modules/register/register.inc.php b/modules/register/register.inc.php index c19dd7e..de4eb8d 100644 --- a/modules/register/register.inc.php +++ b/modules/register/register.inc.php @@ -161,10 +161,9 @@ function createAliases(&$subState) XDB::execute('UPDATE aliases SET expire = ADDDATE(NOW(), INTERVAL 1 MONTH) WHERE alias = {?}', $emailXorg); - XDB::execute('REPLACE INTO homonyms (homonyme_id, uid) - VALUES ({?}, {?})', $subState->i('uid'), $h_id); - XDB::execute('REPLACE INTO homonyms (homonyme_id, uid) - VALUES ({?}, {?})', $h_id, $subState->i('uid')); + XDB::execute('INSERT IGNORE INTO homonyms (homonyme_id, uid) + VALUES ({?}, {?}), ({?}, {?})', + $subState->i('uid'), $h_id, $h_id, $subState->i('uid')); $res = XDB::query('SELECT alias FROM aliases WHERE uid = {?} AND expire IS NULL', $h_id); @@ -199,9 +198,9 @@ function finishRegistration($subState) global $globals; $hash = rand_url_id(12); - XDB::execute('REPLACE INTO register_pending (uid, forlife, bestalias, mailorg2, password, - email, date, relance, naissance, hash, services) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})', + XDB::execute('INSERT INTO register_pending (uid, forlife, bestalias, mailorg2, password, + email, date, relance, naissance, hash, services) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, NOW(), 0, {?}, {?}, {?})', $subState->i('uid'), $subState->s('forlife'), $subState->s('bestalias'), $subState->s('emailXorg2'), $subState->s('password'), $subState->s('email'), $subState->s('birthdate'), $hash, implode(',', $subState->v('services'))); diff --git a/modules/search.php b/modules/search.php index 06c729a..6a2a1e3 100644 --- a/modules/search.php +++ b/modules/search.php @@ -266,9 +266,10 @@ class SearchModule extends PLModule if ($nbResults == 0) { $res = $q."|-2\n"; } - XDB::query('REPLACE INTO search_autocomplete - VALUES ({?}, {?}, {?}, NOW())', - $type, $q, $res); + XDB::query('INSERT INTO search_autocomplete (name, query, result, generated) + VALUES ({?}, {?}, {?}, NOW()) + ON DUPLICATE KEY result = VALUES(result), generated = NOW()', + $type, $q, $res); echo $res; exit(); } diff --git a/modules/xnetevents.php b/modules/xnetevents.php index 7825c1c..e1fe8bf 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -249,13 +249,11 @@ class XnetEventsModule extends PLModule $telepaid= $evt['telepaid'] ? $evt['telepaid'] : 0; foreach ($subs as $j => $nb) { if ($nb >= 0) { - $tmp_flags = (Env::has('notify_payment') ? 'notify_payment' : ''); - $tmp_paid = ($j == 1 ? $paid - $telepaid : 0); XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) VALUES ({?}, {?}, {?}, {?}, {?}, {?}) - ON DUPLICATE KEY UPDATE nb = {?}, flags = {?}, paid = {?}', - $eid, S::v('uid'), $j, $nb, $tmp_flags, $tmp_paid, - $nb, $tmp_flags, $tmp_paid); + ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', + $eid, S::v('uid'), $j, $nb, (Env::has('notify_payment') ? 'notify_payment' : ''), + ($j == 1 ? $paid - $telepaid : 0)); $updated = $eid; } else { XDB::execute( @@ -415,20 +413,15 @@ class XnetEventsModule extends PLModule short_name, deadline_inscription, noinvite, accept_nonmembre) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}) - ON DUPLICATE KEY UPDATE asso_id = {?}, uid = {?}, intitule = {?}, - paiement_id = {?}, descriptif = {?}, debut = {?}, - fin = {?}, show_participants = {?}, short_name = {?}, - deadline_inscription = {?}, noinvite = {?}', + ON DUPLICATE KEY UPDATE asso_id = VALUES(asso_id), uid = VALUES(uid), intitule = VALUES(intitule), + paiement_id = VALUES(paiement_id), descriptif = VALUES(descriptif), debut = VALUES(debut), + fin = VALUES(fin), show_participants = VALUES(show_participants), short_name = VALUES(short_name), + deadline_inscription = VALUES(deadline_inscription), noinvite = VALUES(noinvite)', $evt['eid'], $evt['asso_id'], $evt['uid'], $evt['intitule'], $evt['paiement_id'], $evt['descriptif'], $evt['debut'], $evt['fin'], $evt['show_participants'], $evt['short_name'], $evt['deadline_inscription'], - $evt['noinvite'], $evt['accept_nonmembre'], - $evt['asso_id'], $evt['uid'], - $evt['intitule'], $evt['paiement_id'], $evt['descriptif'], - $evt['debut'], $evt['fin'], $evt['show_participants'], - $evt['short_name'], $evt['deadline_inscription'], - $evt['noinvite'], $evt['accept_nonmembre'], $evt['eid']); + $evt['noinvite'], $evt['accept_nonmembre']); // if new event, get its id if (!$eid) { @@ -443,9 +436,8 @@ class XnetEventsModule extends PLModule $money_defaut += (float)$montant; XDB::execute('INSERT INTO group_event_items (eid, item_id, titre, details, montant) VALUES ({?}, {?}, {?}, {?}, {?}) - ON DUPLICATE KEY UPDATE titre = {?}, details = {?}, montant = {?}', - $eid, $i, Post::v('titre' . $i), Post::v('details' . $i), $montant, - Post::v('titre' . $i), Post::v('details' . $i), $montant); + ON DUPLICATE KEY UPDATE titre = VALUES(titre), details = VALUES(details), montant = VALUES(montant)', + $eid, $i, Post::v('titre' . $i), Post::v('details' . $i), $montant); } else { XDB::execute('DELETE FROM group_event_items WHERE eid = {?} AND item_id = {?}', $eid, $i); @@ -571,9 +563,8 @@ class XnetEventsModule extends PLModule $nb = max(intval($nb), 0); XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) VALUES ({?}, {?}, {?}, {?}, {?}, {?}) - ON DUPLICATE KEY UPDATE nb = {?}, flags = {?}, paid = {?}', - $evt['eid'], $member->uid, $id, $nb, '', ($id == 1 ? $paid : 0), - $nb, '', ($id == 1 ? $paid : 0)); + ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', + $evt['eid'], $member->uid, $id, $nb, '', ($id == 1 ? $paid : 0)); } $res = XDB::query('SELECT COUNT(uid) AS cnt, SUM(nb) AS nb diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index feabfdb..a4ba097 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -198,8 +198,8 @@ function subscribe_lists_event($uid, $evt, $participate, $paid, $payment = false function subscribe($list, $email) { if ($list && $email) { - XDB::execute('REPLACE INTO virtual_redirect - VALUES ({?}, {?})', + XDB::execute('INSERT IGNORE INTO virtual_redirect + VALUES ({?}, {?})', $list, $email); } } diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 9187c47..e0ddcc2 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -700,8 +700,8 @@ class XnetGrpModule extends PLModule } if ($user) { - XDB::execute('REPLACE INTO group_members (uid, asso_id) - VALUES ({?}, {?})', + XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id) + VALUES ({?}, {?})', $user->id(), $globals->asso('id')); $this->removeSubscriptionRequest($user->id()); pl_redirect('member/' . $user->login()); @@ -1172,9 +1172,10 @@ class XnetGrpModule extends PLModule $art['id'], $globals->asso('id')); if ($art['photo'] && $upload->exists()) { list($imgx, $imgy, $imgtype) = $upload->imageInfo(); - XDB::execute("REPLACE INTO group_announces_photo - SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", - $aid, $imgtype, $imgx, $imgy, $upload->getContents()); + XDB::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y) + VALUES ({?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', + $aid, $imgtype, $upload->getContents(), $imgx, $imgy); $upload->rm(); } } -- 2.1.4