function remove($delcomments = true, $permanent = true) { if (!$this->id) { return; } $qry = DBFactory::getDBQuery(); $qry->autocommit(false); event::call('killmail_delete', $this); summaryCache::delKill($this); $qry->execute("delete from kb3_inv_detail where ind_kll_id = " . $this->id); $qry->execute("delete from kb3_inv_all where ina_kll_id = " . $this->id); $qry->execute("delete from kb3_inv_crp where inc_kll_id = " . $this->id); $qry->execute("delete from kb3_items_destroyed where itd_kll_id = " . $this->id); $qry->execute("delete from kb3_items_dropped where itd_kll_id = " . $this->id); // Don't remove comments when readding a kill if ($delcomments) { $qry->execute("delete from kb3_comments where kll_id = " . $this->id); if ($permanent) { //this uses the trust field for a different purpose: to prevent reposts of deleted kills $qry->execute("UPDATE kb3_mails SET kll_trust = -1, kll_modified_time = UTC_TIMESTAMP() WHERE kll_id = " . $this->id); } else { $qry->execute("DELETE FROM kb3_mails WHERE kll_id = " . $this->id); } } $qry->execute("delete from kb3_kills where kll_id = " . $this->id); $qry->autocommit(true); $this->valid = false; Cacheable::delCache($this); }
/** * Set the CCP external ID for this pilot. * * If a character already exists with this id then a name change is assumed * and the old pilot is updated. * @param integer $externalID CCP external ID for this pilot. */ public function setCharacterID($externalID) { $externalID = (int) $externalID; if (!$externalID) { return false; } $this->execQuery(); if (!$this->id) { return false; } else { if ($externalID == $this->externalid) { return true; } } $this->externalid = $externalID; Cacheable::delCache($this); $qry = DBFactory::getDBQuery(true); $qry->execute("SELECT plt_id FROM kb3_pilots WHERE plt_externalid = " . $this->externalid . " AND plt_id <> " . $this->id); if ($qry->recordCount()) { $result = $qry->getRow(); $qry->autocommit(false); $old_id = $result['plt_id']; $qry->execute("UPDATE kb3_kills SET kll_victim_id = " . $old_id . " WHERE kll_victim_id = " . $this->id); $qry->execute("UPDATE kb3_kills SET kll_fb_plt_id = " . $old_id . " WHERE kll_fb_plt_id = " . $this->id); $qry->execute("UPDATE kb3_inv_detail SET ind_plt_id = " . $old_id . " WHERE ind_plt_id = " . $this->id); $qry->execute("DELETE FROM kb3_sum_pilot WHERE psm_plt_id = " . $this->id); $qry->execute("DELETE FROM kb3_sum_pilot WHERE psm_plt_id = " . $old_id); $qry->execute("DELETE FROM kb3_pilots WHERE plt_id = " . $this->id); $qry->execute("UPDATE kb3_pilots SET plt_name = '" . $qry->escape($this->name) . "' where plt_id = " . $old_id); $this->id = $old_id; $qry->autocommit(true); } else { $qry->execute("UPDATE kb3_pilots SET plt_externalid = " . $this->externalid . " WHERE plt_id = " . $this->id); } $this->valid = true; return true; }
/** * Add a new corporation to the database or update the details of an existing one. * * @param string $name The name of the new corporation. * @param Alliance $alliance The alliance this corporation belongs to. * @param string $timestamp The timestamp the corporation's details were updated. * @param integer $externalid The external CCP ID for the corporation. * @param boolean $loadExternals Whether to fetch unknown information from the API. * @return Corporation */ static function add($name, $alliance, $timestamp, $externalid = 0, $loadExternals = true) { if (!$name) { trigger_error("Attempt to add a corporation with no name. Aborting.", E_USER_ERROR); // If things are going this wrong, it's safer to die and prevent more harm die; } else { if (!$alliance->getID()) { trigger_error("Attempt to add a corporation with no alliance. Aborting.", E_USER_ERROR); // If things are going this wrong, it's safer to die and prevent more harm die; } } $name = stripslashes($name); $externalid = (int) $externalid; $qry = DBFactory::getDBQuery(true); $qry->execute("select * from kb3_corps\n\t\t where crp_name = '" . $qry->escape($name) . "'"); // If the corp name is not present in the db add it. if (!$qry->recordCount()) { // If no external id is given then look it up. if (!$externalid && $loadExternals) { $myID = new API_NametoID(); $myID->setNames($name); $myID->fetchXML(); $myNames = $myID->getNameData(); $externalid = (int) $myNames[0]['characterID']; } // If we have an external id then check it isn't already in use // If we find it then update the old corp with the new name and // return. if ($externalid) { $qry->execute("SELECT * FROM kb3_corps WHERE crp_external_id = " . $externalid); if ($qry->recordCount()) { $row = $qry->getRow(); $qry->execute("UPDATE kb3_corps SET crp_name = '" . $qry->escape($name) . "' WHERE crp_external_id = " . $externalid); $crp = Corporation::getByID((int) $row['crp_id']); Cacheable::delCache($crp); $crp->name = $name; $crp->externalid = $row['crp_external_id']; if (!is_null($row['crp_updated'])) { $crp->updated = strtotime($row['crp_updated'] . " UTC"); } else { $crp->updated = null; } // Now check if the alliance needs to be updated. if ($row['crp_all_id'] != $alliance->getID() && $crp->isUpdatable($timestamp)) { $sql = 'update kb3_corps set crp_all_id = ' . $alliance->getID() . ', '; $sql .= "crp_updated = date_format( '" . $timestamp . "','%Y.%m.%d %H:%i:%s') " . "where crp_id = " . $crp->id; $qry->execute($sql); $crp->alliance = $alliance; } return $crp; } } // Neither corp name or external id was found so add this corp as new if ($externalid) { $qry->execute("insert into kb3_corps " . "(crp_name, crp_all_id, crp_external_id, crp_updated) " . "values ('" . $qry->escape($name) . "'," . $alliance->getID() . ", " . $externalid . ", date_format('" . $timestamp . "','%Y.%m.%d %H:%i:%s'))"); } else { $qry->execute("insert into kb3_corps " . "(crp_name, crp_all_id, crp_updated) " . "values ('" . $qry->escape($name) . "'," . $alliance->getID() . ",date_format('" . $timestamp . "','%Y.%m.%d %H:%i:%s'))"); } $crp = Corporation::getByID((int) $qry->getInsertID()); $crp->name = $name; $crp->externalid = (int) $externalid; $crp->alliance = $alliance->getID(); $crp->updated = strtotime(preg_replace("/\\./", "-", $timestamp) . " UTC"); return $crp; } else { $row = $qry->getRow(); $crp = Corporation::getByID((int) $row['crp_id']); $crp->name = $row['crp_name']; $crp->externalid = (int) $row['crp_external_id']; $crp->alliance = $row['crp_all_id']; if (!is_null($row['crp_updated'])) { $crp->updated = strtotime($row['crp_updated'] . " UTC"); } else { $crp->updated = null; } if ($row['crp_all_id'] != $alliance->getID() && $crp->isUpdatable($timestamp)) { $sql = 'update kb3_corps set crp_all_id = ' . $alliance->getID() . ', '; $sql .= "crp_updated = date_format( '" . $timestamp . "','%Y.%m.%d %H:%i:%s') " . "where crp_id = " . $crp->id; $qry->execute($sql); $crp->alliance = $alliance; } if (!$crp->externalid && $externalid) { $crp->setExternalID((int) $externalid); } return $crp; } return false; }