Beispiel #1
0
function update_schema_drop_keys_if_exist($conf, $table, $key)
{
    $indexes = Dbl::fetch_first_columns($conf->dblink, "select distinct index_name from information_schema.statistics where table_schema=database() and `table_name`='{$table}'");
    $drops = [];
    foreach (is_array($key) ? $key : [$key] as $k) {
        if (in_array($k, $indexes)) {
            $drops[] = $k === "PRIMARY" ? "drop primary key" : "drop key `{$k}`";
        }
    }
    if (count($drops)) {
        return $conf->ql("alter table `{$table}` " . join(", ", $drops));
    } else {
        return true;
    }
}
 static function enable($ids, $contact)
 {
     global $Conf;
     $old_logged_errors = Dbl::$logged_errors;
     Dbl::qe("update ContactInfo set disabled=1 where contactId ?a and password='' and contactId!=?", $ids, $contact->contactId);
     $disabled_cids = Dbl::fetch_first_columns("select contactId from ContactInfo where contactId ?a and disabled=1 and contactId!=?", $ids, $contact->contactId);
     if ($disabled_cids) {
         Dbl::qe("update ContactInfo set disabled=0 where contactId ?a", $disabled_cids);
     }
     if (Dbl::$logged_errors > $old_logged_errors) {
         return (object) ["error" => true];
     } else {
         if (!count($disabled_cids)) {
             return (object) ["ok" => true, "warnings" => ["Those accounts were already enabled."]];
         } else {
             $Conf->save_logs(true);
             foreach ($disabled_cids as $cid) {
                 $Conf->log("Account enabled by {$contact->email}", $cid);
             }
             $Conf->save_logs(false);
             return self::modify_password_mail("password='' and contactId!=" . $contact->contactId, true, "create", $disabled_cids);
         }
     }
 }
function do_tags()
{
    global $Conf, $Me, $papersel;
    // check tags
    $tagger = new Tagger($Me);
    $t1 = array();
    $errors = array();
    foreach (preg_split('/[\\s,]+/', (string) @$_REQUEST["tag"]) as $t) {
        if ($t === "") {
            /* nada */
        } else {
            if (!($t = $tagger->check($t, Tagger::NOPRIVATE))) {
                $errors[] = $tagger->error_html;
            } else {
                if (TagInfo::base($t) === "pc") {
                    $errors[] = "The “pc” user tag is set automatically for all PC members.";
                } else {
                    $t1[] = $t;
                }
            }
        }
    }
    if (count($errors)) {
        return Conf::msg_error(join("<br>", $errors));
    } else {
        if (!count($t1)) {
            return $Conf->warnMsg("Nothing to do.");
        }
    }
    // modify database
    Dbl::qe("lock tables ContactInfo write");
    Conf::$no_invalidate_caches = true;
    $users = array();
    if ($_REQUEST["tagtype"] === "s") {
        // erase existing tags
        $likes = array();
        $removes = array();
        foreach ($t1 as $t) {
            list($tag, $index) = TagInfo::split_index($t);
            $removes[] = $t;
            $likes[] = "contactTags like " . Dbl::utf8ci("'% " . sqlq_for_like($tag) . "#%'");
        }
        foreach (Dbl::fetch_first_columns(Dbl::qe("select contactId from ContactInfo where " . join(" or ", $likes))) as $cid) {
            $users[(int) $cid] = (object) array("id" => (int) $cid, "add_tags" => [], "remove_tags" => $removes);
        }
    }
    // account for request
    $key = $_REQUEST["tagtype"] === "d" ? "remove_tags" : "add_tags";
    foreach ($papersel as $cid) {
        if (!isset($users[(int) $cid])) {
            $users[(int) $cid] = (object) array("id" => (int) $cid, "add_tags" => [], "remove_tags" => []);
        }
        $users[(int) $cid]->{$key} = array_merge($users[(int) $cid]->{$key}, $t1);
    }
    // apply modifications
    foreach ($users as $cid => $cj) {
        $us = new UserStatus(array("send_email" => false));
        if (!$us->save($cj)) {
            $errors = array_merge($errors, $us->error_messages());
        }
    }
    Dbl::qe("unlock tables");
    Conf::$no_invalidate_caches = false;
    $Conf->invalidateCaches(["pc" => true]);
    // report
    if (!count($errors)) {
        $Conf->confirmMsg("Tags saved.");
        redirectSelf(array("tagact" => null, "tag" => null));
    } else {
        Conf::msg_error(join("<br>", $errors));
    }
}
 function alternate_query()
 {
     if ($this->q !== "" && $this->q[0] !== "#" && preg_match('/\\A' . TAG_REGEX . '\\z/', $this->q)) {
         if ($this->q[0] === "~") {
             return "#" . $this->q;
         }
         $result = Dbl::qe("select paperId from PaperTag where tag=? limit 1", $this->q);
         if (count(Dbl::fetch_first_columns($result))) {
             return "#" . $this->q;
         }
     }
     return false;
 }