X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fnewsletter.inc.php;h=bccf89fccda33c91f0f63e8465f3c407182e9582;hb=4d9b63f8ec02d84eabd554234a32718758bf9e21;hp=a8c424ea3d6937702131c37324fd0eb0232c8815;hpb=9f5bd98e936d8cef7ca9f774eeef64dbb8a1b079;p=platal.git diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index a8c424e..bccf89f 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -92,22 +92,27 @@ class NewsLetter extends MassMailer public function saveArticle(&$a) { + $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) @@ -133,7 +138,7 @@ class NewsLetter extends MassMailer $user = is_null($uid) ? S::v('uid') : $uid; $res = XDB::query("SELECT 1 FROM newsletter_ins - WHERE user_id={?}", $user); + WHERE uid={?}", $user); return $res->fetchOneCell(); } @@ -141,14 +146,14 @@ class NewsLetter extends MassMailer { $user = is_null($uid) ? S::v('uid') : $uid; XDB::execute("DELETE FROM newsletter_ins - WHERE user_id={?}", $user); + WHERE uid={?}", $user); } static public function subscribe($uid = null) { $user = is_null($uid) ? S::v('uid') : $uid; - XDB::execute("REPLACE INTO newsletter_ins (user_id,last) - VALUES ({?}, 0)", $user); + XDB::execute('INSERT IGNORE INTO newsletter_ins (uid, last, hash) + VALUES ({?}, NULL, NULL)', $user); } protected function subscriptionWhere()