/** * Purges session events without a valid session. */ function purgeOrphanedEvents() { $begin = time(); XDB::execute("DELETE e\n FROM log_events AS e\n LEFT JOIN log_sessions AS s ON (s.id = e.session)\n WHERE s.id IS NULL"); $affectedRows = XDB::affectedRows(); $duration = time() - $begin; echo "Orphaned events: removed {$affectedRows} events in {$duration} seconds.\n"; }
function handler_ajax_todo_clear($page) { S::assert_xsrf_token(); XDB::execute('DELETE FROM todo WHERE uid = {?} AND checked = 1', S::user()->id()); if (XDB::affectedRows() != 1) { $page->jsonAssign('error', "Impossible de nettoyer la liste des tâches"); } return PL_JSON; }
public function commit() { global $globals; $email = $this->m_user->bestEmail(); XDB::execute('UPDATE email_redirect_account SET flags = \'active\', broken_level = 2 WHERE uid = {?} AND redirect = {?}', $this->m_user->id(), $this->m_email); if (XDB::affectedRows() > 0) { $this->m_reactive = true; $mailer = new PlMailer(); $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>'); $mailer->addTo($email); $mailer->setSubject("Mise à jour de ton adresse {$email}"); $mailer->setTxtBody(wordwrap("Cher Camarade,\n\n" . "Ton adresse {$email} étant en panne et ayant été informés que ta redirection {$this->m_email}, jusqu'à présent inactive, " . "est fonctionnelle, nous venons de réactiver cette adresse.\n\n" . "N'hésite pas à aller gérer toi-même tes redirections en te rendant à la page :\n" . "https://www.polytechnique.org/emails/redirect\n" . "Si tu as perdu ton mot de passe d'accès au site, tu peux également effectuer la procédure de récupération à l'adresse :\n" . "https://www.polytechnique.org/recovery\n\n" . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n")); $mailer->send(); return true; } if ($this->m_user->email) { $subject = "Ton adresse {$email} semble ne plus fonctionner"; $reason = "Nous avons été informés que ton adresse {$email} ne fonctionne plus correctement par un camarade"; } else { $res = XDB::iterRow('SELECT redirect FROM email_redirect_account WHERE uid = {?} AND flags = \'broken\'', $this->m_user->id()); $redirect = array(); while (list($red) = $res->next()) { list(, $redirect[]) = explode('@', $red); } $subject = "Ton adresse {$email} ne fonctionne plus"; $reason = "Ton adresse {$email} ne fonctionne plus"; if (!count($redirect)) { $reason .= '.'; } elseif (count($redirect) == 1) { $reason .= ' car sa redirection vers ' . $redirect[0] . ' est hors-service depuis plusieurs mois.'; } else { $reason .= ' car ses redirections vers ' . implode(', ', $redirect) . ' sont hors-services depuis plusieurs mois.'; } } $body = ($this->m_user->isFemale() ? 'Chère ' : 'Cher ') . $this->m_user->displayName() . ",\n\n" . $reason . "\n\n" . "L'adresse {$this->m_email} nous a été communiquée, veux-tu que cette adresse devienne ta nouvelle " . "adresse de redirection ? Si oui, envoie nous des informations qui " . "nous permettront de nous assurer de ton identité (par exemple ta date de naissance et ta promotion).\n\n" . "-- \nTrès Cordialement,\nL'Équipe de Polytechnique.org\n"; $body = wordwrap($body, 78); $mailer = new PlMailer(); $mailer->setFrom('"Association Polytechnique.org" <register@' . $globals->mail->domain . '>'); $mailer->addTo($this->m_email); $mailer->setSubject($subject); $mailer->setTxtBody($body); return $mailer->send(); }
foreach ($tables as $table => $keys) { $res = XDB::query("SELECT * FROM geoloc_{$table}"); if (!$res) { echo "{$table}\n"; continue; } $all = $res->fetchAllAssoc(); foreach ($all as &$array) { $from = array(); $to = array(); foreach ($array as $key => $value) { if (in_array($key, $keys)) { $from[] = $key . '=' . XDB::escape($value); } $valued = utf8_decode($value); if (is_utf8($value) && $valued != $value) { $to[] = $key . '=' . XDB::escape($valued); } } if (!empty($to)) { $to = implode(', ', $to); $from = implode(' AND ', $from); $sql = "UPDATE geoloc_{$table} SET {$to} WHERE {$from}"; if (!XDB::execute($sql)) { echo "Echec : {$sql}\n"; } elseif (XDB::affectedRows() == 0) { echo "{$sql}\n"; } } } }
public function delRegistered(PlPage $page, Profile $profile) { XDB::execute('DELETE FROM contacts WHERE uid = {?} AND contact = {?}', S::i('uid'), $profile->id()); if (XDB::affectedRows() > 0) { S::user()->invalidWatchCache(); Platal::session()->updateNbNotifs(); $page->trigSuccess("Contact retiré !"); } }
/*************************************************************************** * Copyright (C) 2003-2015 Polytechnique.org * * http://opensource.polytechnique.org/ * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software * * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ***************************************************************************/ require './connect.db.inc.php'; $it = 0; do { XDB::execute('UPDATE profiles SET next_birthday = DATE_ADD(next_birthday, INTERVAL 1 YEAR) WHERE (next_birthday != 0 AND next_birthday IS NOT NULL AND next_birthday < CURDATE()) AND deathdate IS NULL'); ++$it; $affected = XDB::affectedRows(); //echo "Iteration $it => $affected changes\n"; } while ($affected > 0); // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
public function run() { global $platal, $globals; // Update last unread time $time = null; if (!is_null($this->params) && isset($this->params['updateall'])) { $time = intval($this->params['updateall']); $this->user->banana_last = $time; } $infos = $this->fetchProfile(); if ($infos['maj']) { $time = time(); } // Build user profile $req = XDB::query("SELECT name\n FROM forum_subs AS fs\n LEFT JOIN forums AS f ON (f.fid = fs.fid)\n WHERE uid={?}", $this->user->id()); Banana::$profile['headers']['From'] = $infos['name'] . ' <' . $infos['mail'] . '>'; Banana::$profile['headers']['Organization'] = make_Organization(); Banana::$profile['signature'] = $infos['sig']; Banana::$profile['display'] = $infos['threads']; Banana::$profile['autoup'] = $infos['maj']; Banana::$profile['lastnews'] = $this->user->banana_last; Banana::$profile['subscribe'] = $req->fetchColumn(); Banana::$tree_unread = $infos['tree_unread']; Banana::$tree_read = $infos['tree_read']; // Update the "unread limit" if (!is_null($time)) { XDB::execute('UPDATE forum_profiles SET last_seen = FROM_UNIXTIME({?}) WHERE uid = {?}', $time, $this->user->id()); if (XDB::affectedRows() == 0) { XDB::execute('INSERT IGNORE INTO forum_profiles (uid, last_seen) VALUES ({?}, FROM_UNIXTIME({?}))', $this->user->id(), $time); } } if (!empty($GLOBALS['IS_XNET_SITE'])) { Banana::$page->killPage('forums'); Banana::$page->killPage('subscribe'); Banana::$spool_boxlist = false; } else { // Register custom Banana links and tabs if (!Banana::$profile['autoup']) { Banana::$page->registerAction('<a href=\'javascript:$.dynPost("' . $platal->path . '", "updateall", ' . time() . ')\'>' . 'Marquer tous les messages comme lus' . '</a>', array('forums', 'thread', 'message')); } Banana::$page->registerPage('profile', 'Préférences', null); } // Run Bananai if (Banana::$action == 'profile') { Banana::$page->run(); return $this->action_updateProfile(); } else { return parent::run(); } }
public function delete() { XDB::execute('DELETE FROM profile_addresses_components WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', $this->pid, $this->jobid, $this->groupid, $this->type, $this->id); XDB::execute('DELETE FROM profile_addresses WHERE pid = {?} AND jobid = {?} AND groupid = {?} AND type = {?} AND id = {?}', $this->pid, $this->jobid, $this->groupid, $this->type, $this->id); return XDB::affectedRows(); }
/** Lier les identifiants d'un ancien dans les deux annuaires * @param user_id identifiant dans l'annuaire X.org * @param matricule_ax identifiant dans l'annuaire de l'AX * @return 0 si la liaison a échoué, 1 sinon */ private static function link_by_ids($pid, $ax_id) { $res = XDB::execute('UPDATE fusionax_import AS i INNER JOIN fusionax_xorg_anciens AS u SET u.ax_id = i.ax_id, i.pid = u.pid, i.date_match_id = NOW() WHERE i.ax_id = {?} AND u.pid = {?} AND (u.ax_id != {?} OR u.ax_id IS NULL OR i.pid != {?} OR i.pid IS NULL)', $ax_id, $pid, $ax_id, $pid); if (!$res) { return 0; } return XDB::affectedRows() / 2; }
/** Save the global properties of this NL issue (title&co). */ public function save() { $errors = array(); // Fill the list of fields to update $fields = array('title' => $this->title, 'mail_title' => $this->title_mail, 'head' => $this->head, 'signature' => $this->signature); if (!empty($this->reply_to) && !isvalid_email($this->reply_to)) { $errors[] = self::ERROR_INVALID_REPLY_TO; } else { $fields['reply_to'] = $this->reply_to; } if ($this->isEditable()) { $fields['date'] = $this->date; if (!preg_match('/^[-a-z0-9]+$/i', $this->shortname) || is_numeric($this->shortname)) { $errors[] = self::ERROR_INVALID_SHORTNAME; } else { $fields['short_name'] = $this->shortname; } if ($this->sufb->isValid() || $this->sufb->isEmpty()) { $fields['sufb_json'] = json_encode($this->sufb->export()->dict()); // If sufb_json is too long to be store, we do not store a truncated json and notify the user. // The limit is LONGTEXT's one, ie 2^32 = 4294967296. if (strlen($fields['sufb_json']) > 4294967295) { $errors[] = self::ERROR_TOO_LONG_UFC; } } else { $errors[] = self::ERROR_INVALID_UFC; } if ($this->nl->automaticMailingEnabled()) { $fields['send_before'] = $this->send_before ? $this->send_before : null; } } if (count($errors)) { return $errors; } $field_sets = array(); foreach ($fields as $key => $value) { $field_sets[] = XDB::format($key . ' = {?}', $value); } XDB::execute('UPDATE newsletter_issues SET ' . implode(', ', $field_sets) . ' WHERE id={?}', $this->id); if (XDB::affectedRows()) { $this->refresh(); } else { $errors[] = self::ERROR_SQL_SAVE; } return $errors; }
protected function _saveData() { if ($this->changed['nationality1'] || $this->changed['nationality2'] || $this->changed['nationality3'] || $this->changed['birthdate'] || $this->changed['freetext'] || $this->changed['freetext_pub'] || $this->changed['axfreetext'] || $this->changed['email_directory'] || $this->changed['profile_title']) { if ($this->values['nationality3'] == "") { $this->values['nationality3'] = NULL; } if ($this->values['nationality2'] == "") { $this->values['nationality2'] = $this->values['nationality3']; $this->values['nationality3'] = NULL; } if ($this->values['nationality1'] == "") { $this->values['nationality1'] = $this->values['nationality2']; $this->values['nationality2'] = $this->values['nationality3']; $this->values['nationality3'] = NULL; } if ($this->values['nationality1'] == $this->values['nationality2'] && $this->values['nationality2'] == $this->values['nationality3']) { $this->values['nationality2'] = NULL; $this->values['nationality3'] = NULL; } else { if ($this->values['nationality1'] == $this->values['nationality2']) { $this->values['nationality2'] = $this->values['nationality3']; $this->values['nationality3'] = NULL; } else { if ($this->values['nationality2'] == $this->values['nationality3'] || $this->values['nationality1'] == $this->values['nationality3']) { $this->values['nationality3'] = NULL; } } } $new_email = $this->values['email_directory'] == "*****@*****.**" ? $this->values['email_directory_new'] : $this->values['email_directory']; if ($new_email == "") { $new_email = NULL; } XDB::execute("UPDATE profiles\n SET nationality1 = {?}, nationality2 = {?}, nationality3 = {?}, birthdate = {?},\n freetext = {?}, freetext_pub = {?}, axfreetext = {?}, email_directory = {?}, title = {?}\n WHERE pid = {?}", $this->values['nationality1'], $this->values['nationality2'], $this->values['nationality3'], ProfileSettingDate::toSQLDate($this->values['birthdate']), $this->values['freetext'], $this->values['freetext_pub'], $this->values['axfreetext'], $new_email, $this->values['profile_title'], $this->pid()); } if ($this->changed['photo_pub']) { XDB::execute("UPDATE profile_photos\n SET pub = {?}\n WHERE pid = {?}", $this->values['photo_pub'], $this->pid()); } if (S::user()->isMe($this->owner) && $this->changed['yourself']) { if ($this->owner) { XDB::execute('UPDATE accounts SET display_name = {?} WHERE uid = {?}', $this->values['yourself'], $this->owner->id()); } XDB::execute('UPDATE profile_display SET yourself = {?} WHERE pid = {?}', $this->values['yourself'], $this->pid()); } if ($this->changed['promo_display']) { if ($this->values['promo_display'][0] == $this->profile->mainEducation()) { $yearpromo = intval(substr($this->values['promo_display'], 1, 4)); if ($this->profile->mainEducation() == 'X' && $yearpromo >= $this->profile->entry_year || $this->profile->mainEducation() != 'X' && $yearpromo >= $this->profile->entry_year + $this->profile->mainEducationDuration()) { XDB::execute('UPDATE profile_display SET promo = {?} WHERE pid = {?}', $this->values['promo_display'], $this->pid()); XDB::execute('UPDATE profile_education SET promo_year = {?} WHERE pid = {?} AND FIND_IN_SET(\'primary\', flags)', $yearpromo, $this->pid()); } } } if ($this->changed['birthdate_ref'] && S::admin() && !$this->owner->perms) { XDB::execute('UPDATE profiles SET birthdate_ref = {?} WHERE pid = {?}', ProfileSettingDate::toSQLDate($this->values['birthdate_ref']), $this->pid()); } if (!S::user()->isMe($this->owner) && $this->changed['deathdate']) { XDB::execute('UPDATE profiles SET deathdate = {?}, deathdate_rec = NOW() WHERE pid = {?} AND deathdate_rec IS NULL', ProfileSettingDate::toSQLDate($this->values['deathdate']), $this->pid()); if (XDB::affectedRows() > 0) { $this->profile->clear(); if ($this->owner) { $this->owner->clear(true); } } else { /* deathdate_rec was not NULL, this is just an update of the death date */ XDB::execute('UPDATE profiles SET deathdate = {?} WHERE pid = {?}', ProfileSettingDate::toSQLDate($this->values['deathdate']), $this->pid()); } } }
public function removeMinimodule(FrankizMiniModule $m) { $rmName = $m->name(); XDB::execute('DELETE FROM users_minimodules WHERE uid = {?} AND name = {?}', $this->id(), $rmName); if (XDB::affectedRows() > 0) { $cols = array_keys(FrankizMiniModule::emptyLayout()); foreach ($cols as $col) { $this->minimodules[$col] = array_filter($this->minimodules[$col], function ($name) use($rmName) { return $name != $rmName; }); } return true; } return false; }
function handler_admin_member($page, $user) { global $globals; $user = User::getSilent($user); if (empty($user)) { return PL_NOT_FOUND; } if (!$user->inGroup($globals->asso('id'))) { pl_redirect('annuaire'); } $page->changeTpl('xnetgrp/membres-edit.tpl'); $page->addJsLink('xnet_members.js'); $mmlist = new MMList(S::user(), $globals->asso('mail_domain')); if (Post::has('change')) { S::assert_xsrf_token(); require_once 'emails.inc.php'; require_once 'name.func.inc.php'; // Convert user status to X if (!Post::blank('x')) { $forlife = $this->changeLogin($page, $user, Post::i('userid'), Post::b('broken'), Post::b('marketing'), Post::v('marketing_from')); if ($forlife) { pl_redirect('member/' . $forlife); } } // Update user info if ($user->type == 'virtual' || $user->type == 'xnet' && !$user->perms) { $lastname = capitalize_name(Post::t('lastname')); if (Post::s('type') != 'virtual') { $firstname = capitalize_name(Post::t('firstname')); } else { $firstname = ''; } $full_name = build_full_name($firstname, $lastname); $directory_name = build_directory_name($firstname, $lastname); $sort_name = build_sort_name($firstname, $lastname); XDB::query('UPDATE accounts SET full_name = {?}, directory_name = {?}, sort_name = {?}, display_name = {?}, firstname = {?}, lastname = {?}, sex = {?}, type = {?} WHERE uid = {?}', $full_name, $directory_name, $sort_name, Post::t('display_name'), $firstname, $lastname, Post::t('sex') == 'male' ? 'male' : 'female', Post::t('type') == 'xnet' ? 'xnet' : 'virtual', $user->id()); } // Updates email. $new_email = strtolower(Post::t('email')); if (($user->type == 'virtual' || $user->type == 'xnet' && !$user->perms) && require_email_update($user, $new_email)) { XDB::query('UPDATE accounts SET email = {?} WHERE uid = {?}', $new_email, $user->id()); if ($user->forlifeEmail()) { $listClient = new MMList(S::user()); $listClient->change_user_email($user->forlifeEmail(), $new_email); update_alias_user($user->forlifeEmail(), $new_email); } $user = User::getWithUID($user->id()); } if (XDB::affectedRows()) { $page->trigSuccess('Données de l\'utilisateur mises à jour.'); } if ($user->type == 'xnet' && !$user->perms) { if (Post::b('suggest')) { $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom'), $globals->asso('diminutif')); $request->submit(); $page->trigSuccess('Le compte va bientôt être activé.'); } if (Post::b('again')) { $this->again($user->id()); $page->trigSuccess('Relance effectuée avec succès.'); } } // Update group params for user $perms = Post::v('group_perms'); $comm = Post::t('comm'); $position = Post::t('group_position') == '' ? null : Post::v('group_position'); if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) { XDB::query('UPDATE group_members SET perms = {?}, comm = {?}, position = {?} WHERE uid = {?} AND asso_id = {?}', $perms == 'admin' ? 'admin' : 'membre', $comm, $position, $user->id(), $globals->asso('id')); if (XDB::affectedRows()) { if ($perms != $user->group_perms) { $page->trigSuccess('Permissions modifiées !'); } if ($comm != $user->group_comm) { $page->trigSuccess('Commentaire mis à jour.'); } if ($position != $user->group_position) { $page->trigSuccess('Poste mis à jour.'); } } } // Gets user info again as they might have change $user = User::getSilent($user->id()); // Update ML subscriptions foreach (Env::v('ml1', array()) as $ml => $state) { $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; if ($ask == $state) { continue; } if ($state == '1') { $page->trigWarning("{$user->fullName()} a " . "actuellement une demande d'inscription en " . "cours sur <strong>{$ml}@</strong> !!!"); } elseif ($ask) { $mmlist->mass_subscribe($ml, array($user->forlifeEmail())); $page->trigSuccess("{$user->fullName()} a été abonné à {$ml}@."); } else { $mmlist->mass_unsubscribe($ml, array($user->forlifeEmail())); $page->trigSuccess("{$user->fullName()} a été désabonné de {$ml}@."); } } // Change subscriptioin to aliases foreach (Env::v('ml3', array()) as $ml => $state) { require_once 'emails.inc.php'; $ask = !empty($_REQUEST['ml4'][$ml]); list($local_part, ) = explode('@', $ml); if ($ask == $state) { continue; } if ($ask) { add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain')); $page->trigSuccess("{$user->fullName()} a été abonné à {$ml}."); } else { delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain')); $page->trigSuccess("{$user->fullName()} a été désabonné de {$ml}."); } } if ($globals->asso('has_nl')) { $nl = NewsLetter::forGroup($globals->asso('shortname')); // Updates group's newsletter subscription. if (Post::i('newsletter') == 1) { $nl->subscribe($user); } else { $nl->unsubscribe(null, $user->id()); } } } $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\''); $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']); if ($globals->asso('has_nl')) { $nl = NewsLetter::forGroup($globals->asso('shortname')); $nl_registered = $nl->subscriptionState($user); } else { $nl_registered = false; } $page->assign('user', $user); $page->assign('suggest', $this->suggest($user)); $page->assign('listes', $mmlist->get_lists($user->forlifeEmail())); $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain'))); $page->assign('positions', explode(',', $positions)); $page->assign('nl_registered', $nl_registered); $page->assign('pending_xnet_account', XDB::fetchOneCell('SELECT 1 FROM register_pending_xnet WHERE uid = {?}', $user->id())); }
public function commit() { $res = XDB::query('SELECT id FROM profile_job_enum WHERE name = {?}', $this->name); if ($res->numRows() != 1) { XDB::execute('INSERT INTO profile_job_enum (name, acronym, url, email, holdingid, SIREN_code, NAF_code, AX_code) VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $this->name, $this->acronym, $this->url, $this->email, $this->holdingid, $this->SIREN, $this->NAF_code, $this->AX_code); $jobid = XDB::insertId(); $phone = new Phone(array('link_type' => 'hq', 'link_id' => $jobid, 'id' => 0, 'type' => 'fixed', 'display' => $this->tel, 'pub' => 'public')); $fax = new Phone(array('link_type' => 'hq', 'link_id' => $jobid, 'id' => 1, 'type' => 'fax', 'display' => $this->fax, 'pub' => 'public')); $address = new Address(array('jobid' => $jobid, 'type' => Address::LINK_COMPANY, 'text' => $this->address)); $phone->save(); $fax->save(); $address->save(); } else { $jobid = $res->fetchOneCell(); } XDB::execute('UPDATE profile_job SET jobid = {?} WHERE pid = {?} AND id = {?}', $jobid, $this->profile->id(), $this->id); if (XDB::affectedRows() == 0) { return XDB::execute('INSERT INTO profile_job (jobid, pid, id) VALUES ({?}, {?}, {?})', $jobid, $this->profile->id(), $this->id); } return true; }
/** * Helper to remove a value from a FlagSet which is in the database * * @param string $field Object field * @param mixed $value the value to remove * @return true if something has been modified, false otherwise */ protected function helper_flagsetRemove($field, $value) { $className = get_class($this); $schema = Schema::get($className); $id = $schema->id(); list($table, $column) = $schema->flagsetType($field); XDB::execute("DELETE FROM {$table}\n WHERE {$id} = {?} AND {$column} = {?}\n LIMIT 1", $this->id(), $value); if (!(XDB::affectedRows() > 0)) { return false; } if (empty($this->{$field})) { $this->{$field} = new PlFlagSet(); } $this->{$field}->rmFlag($value); return true; }
XDB::rawExecute('UPDATE fusionax_formations AS f LEFT JOIN profile_education_enum AS pe ON (pe.name = f.Intitule_formation) LEFT JOIN profile_education_degree_enum AS pd ON (pd.abbreviation = f.Intitule_diplome) LEFT JOIN profile_education_field_enum AS pf ON (pf.field = f.Descr_formation) SET f.eduid = pe.id, f.degreeid = pd.id, f.fieldid = pf.id'); XDB::rawExecute('ALTER TABLE profile_education_enum DROP INDEX name'); XDB::rawExecute('ALTER TABLE profile_education_degree_enum DROP INDEX abbreviation'); // Updates non complete educations. XDB::rawExecute("UPDATE profile_education AS e\n INNER JOIN fusionax_formations AS f ON (f.pid = e.pid)\n INNER JOIN profile_education_degree_enum AS pd ON (e.degreeid = pd.id)\n INNER JOIN profile_education_degree_enum AS fd ON (f.degreeid = fd.id)\n SET e.eduid = f.eduid\n WHERE NOT FIND_IN_SET('primary', e.flags) AND e.eduid IS NULL AND pd.level = fd.level"); XDB::rawExecute("UPDATE profile_education AS e\n INNER JOIN fusionax_formations AS f ON (f.pid = e.pid)\n SET e.degreeid = f.degreeid\n WHERE NOT FIND_IN_SET('primary', e.flags) AND e.degreeid IS NULL AND e.eduid = f.eduid"); // Deletes duplicates. XDB::rawExecute("DELETE f\n FROM fusionax_formations AS f\n INNER JOIN profile_education_degree_enum AS fd ON (fd.abbreviation = f.Intitule_diplome)\n INNER JOIN profile_education AS e ON (e.pid = f.pid AND NOT FIND_IN_SET('primary', e.flags))\n INNER JOIN profile_education_degree_enum AS pd ON (pd.id = e.degreeid)\n WHERE f.eduid = e.eduid AND fd.level = pd.level"); // Updates merge_issues table. XDB::rawExecute("UPDATE profile_merge_issues AS pm\n INNER JOIN fusionax_formations AS f ON (f.pid = pm.pid)\n SET pm.issues = IF(pm.issues, CONCAT(pm.issues, ',', 'education'), 'education')"); XDB::rawExecute("INSERT IGNORE INTO profile_merge_issues (pid, issues)\n SELECT pid, 'education'\n FROM fusionax_formations"); $id = 0; $continue = 1; while ($continue > 0) { XDB::rawExecute("INSERT IGNORE INTO profile_education (id, pid, eduid, degreeid, fieldid, program)\n SELECT {$id}, pid, eduid, degreeid, fieldid, Descr_formation\n FROM fusionax_formations"); XDB::rawExecute("DELETE f\n FROM fusionax_formations AS f\n INNER JOIN profile_education AS pe ON (pe.pid = f.pid AND pe.id = {$id})\n WHERE (pe.eduid = f.eduid OR (pe.eduid IS NULL AND f.eduid IS NULL))\n AND (pe.degreeid = f.degreeid OR (pe.degreeid IS NULL AND f.degreeid IS NULL))\n AND (pe.fieldid = f.fieldid OR (pe.fieldid IS NULL AND f.fieldid IS NULL))\n AND (pe.program = f.Descr_formation OR (pe.program IS NULL AND f.Descr_formation IS NULL))"); $continue = XDB::affectedRows(); ++$id; } // Updates merge_issues table (eduid and degreeid should never be empty). XDB::rawExecute("UPDATE profile_merge_issues AS pm\n INNER JOIN profile_education AS pe ON (pe.pid = pm.pid)\n SET pm.issues = CONCAT(pm.issues, ',', 'education')\n WHERE NOT FIND_IN_SET('education', pm.issues) AND (pe.eduid = '' OR pe.eduid IS NULL OR pe.degreeid = '' OR pe.degreeid IS NULL)"); XDB::rawExecute("INSERT IGNORE INTO profile_merge_issues (pid, issues)\n SELECT pid, 'education'\n FROM profile_education\n WHERE eduid = '' OR eduid IS NULL OR degreeid = '' OR degreeid IS NULL"); XDB::rawExecute('DROP TABLE IF EXISTS fusionax_formations'); echo "Educations inclusions finished.\n"; echo "All inclusions are done.\n"; XDB::commit(); /* vim:set et sw=4 sts=4 ts=4: */