Example #1
0
 /**
  * Add row to the redirect table if this is a redirect, remove otherwise. 
  *
  * @param Database $dbw
  * @param $redirectTitle a title object pointing to the redirect target,
  * 							or NULL if this is not a redirect  
  * @param bool $lastRevIsRedirect If given, will optimize adding and 
  * 							removing rows in redirect table.
  * @return bool true on success, false on failure
  * @private
  */
 function updateRedirectOn(&$dbw, $redirectTitle, $lastRevIsRedirect = null)
 {
     // Always update redirects (target link might have changed)
     // Update/Insert if we don't know if the last revision was a redirect or not
     // Delete if changing from redirect to non-redirect
     $isRedirect = !is_null($redirectTitle);
     if ($isRedirect || is_null($lastRevIsRedirect) || $lastRevIsRedirect !== $isRedirect) {
         wfProfileIn(__METHOD__);
         if ($isRedirect) {
             // This title is a redirect, Add/Update row in the redirect table
             $set = array('rd_namespace' => $redirectTitle->getNamespace(), 'rd_title' => $redirectTitle->getDBkey(), 'rd_from' => $this->getId());
             $dbw->replace('redirect', array('rd_from'), $set, __METHOD__);
         } else {
             // This is not a redirect, remove row from redirect table
             $where = array('rd_from' => $this->getId());
             $dbw->delete('redirect', $where, __METHOD__);
         }
         wfProfileOut(__METHOD__);
         return $dbw->affectedRows() != 0;
     }
     return true;
 }
Example #2
0
 /**
  * @return int
  */
 public function upgrade()
 {
     $change_column_num = 0;
     $table_name = $this->getTableName();
     $columns = $this->getDBColumns();
     $index_columns = $this->getIndexColumns();
     $reference_columns = $this->getDBReferenceColumn();
     if ($this->db->checkTableExists($table_name)) {
         $results = $this->db->getTableColumns($table_name);
         $results_index = $this->db->getTableIndex($table_name);
         //$results_foreignkey = $this->db->getTableForeignKey($table_name);
         $add_columns = array();
         $add_index_columns = array();
         $change_columns = array();
         $delete_columns = array();
         $delete_indexs = array();
         $delete_foreignkey = array();
         $columns_keys = array_keys($columns);
         foreach ($columns as $k => $v) {
             if (isset($results[$k])) {
                 if (!$v->isEqual($results[$k])) {
                     $change_columns[$k] = $v;
                 }
             } else {
                 $add_columns[$k] = $v;
             }
         }
         foreach ($results as $k => $v) {
             if (!isset($columns[$k])) {
                 $delete_columns[$k] = $v;
             }
         }
         foreach ($index_columns as $k => $v) {
             if (isset($results_index[$k])) {
                 //$change_columns[$k] = $v;
             } else {
                 $add_index_columns[$k] = $v;
             }
         }
         foreach ($results_index as $k) {
             if ($k == "PRIMARY") {
                 continue;
             }
             if (preg_match('/^(.+_fk)$/', $k, $matchs)) {
                 if (!preg_match('/^(.+)_(.+_fk)$/', $matchs[1], $mt) || !isset($reference_columns[$mt[2]])) {
                     $delete_foreignkey[$k] = $k;
                 }
                 continue;
             }
             if (!isset($index_columns[$k])) {
                 $delete_indexs[$k] = $k;
             }
         }
         // update
         foreach ($delete_foreignkey as $k) {
             if ($this->db->dropForeignKey($table_name, $k) && $this->db->affectedRows() > 0) {
                 $change_column_num++;
             }
         }
         foreach ($delete_columns as $k => $v) {
             if ($this->db->alterTableDrop($table_name, $k) && $this->db->affectedRows() > 0) {
                 $change_column_num++;
             }
         }
         foreach ($delete_indexs as $k => $v) {
             if ($this->db->alterTableDropIndex($table_name, $k) && $this->db->affectedRows() > 0) {
                 $change_column_num++;
             }
         }
         foreach ($change_columns as $k => $v) {
             if ($this->db->alterTableChange($table_name, $k, $v, $k) && $this->db->affectedRows() > 0) {
                 $change_column_num++;
             }
         }
         foreach ($add_columns as $k => $v) {
             $current_key = array_search($k, $columns_keys);
             if ($this->db->alterTableAdd($table_name, $k, $v, $current_key > 0 ? $this->db->escapeColumn($columns_keys[$current_key - 1]) : "FIRST") && $this->db->affectedRows() > 0) {
                 $change_column_num++;
             }
         }
         foreach ($add_index_columns as $k => $v) {
             if ($this->db->alterTableAddIndex($table_name, $v->generateName(), $v->getFields()) && $this->db->affectedRows() > 0) {
                 $change_column_num++;
             }
         }
         // update callback
         $this->modelUpdate();
     } else {
         if ($result = $this->db->createTable($table_name, $columns, $this->table_options) && $this->db->affectedRows() > 0) {
             $change_column_num++;
         }
         // update callback
         $this->modelUpdate();
     }
     return $change_column_num;
 }
Example #3
0
 /**
 * Update the page record to point to a newly saved revision.
 *
 * @param Database $dbw
 * @param Revision $revision For ID number, and text used to set
                             length and redirect status fields
 * @param int $lastRevision If given, will not overwrite the page field
 *                          when different from the currently set value.
 *                          Giving 0 indicates the new page flag should
 *                          be set on.
 * @return bool true on success, false on failure
 * @private
 */
 function updateRevisionOn(&$dbw, $revision, $lastRevision = null)
 {
     wfProfileIn(__METHOD__);
     $conditions = array('page_id' => $this->getId());
     if (!is_null($lastRevision)) {
         # An extra check against threads stepping on each other
         $conditions['page_latest'] = $lastRevision;
     }
     $text = $revision->getText();
     $dbw->update('page', array('page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp(), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => Article::isRedirect($text) ? 1 : 0, 'page_len' => strlen($text)), $conditions, __METHOD__);
     wfProfileOut(__METHOD__);
     return $dbw->affectedRows() != 0;
 }
    if (isset($_POST['form_insert']) && isset($_POST['google_insert']) && trim($_POST['google_link']) != '' && trim($_POST['google_date']) != '' && $_POST['google_project'] != '') {
        $arraySource = array();
        $arrayDate = explode(' ', $_POST['google_date']);
        $month = $arrayDate[0];
        $year = $arrayDate[1];
        foreach ($_POST as $key => $value) {
            $arraySource['link'] = $_POST['google_link'];
            $arraySource['link_month'] = $month;
            $arraySource['link_year'] = $year;
            $arraySource['project_link'] = $_POST['google_project'];
        }
        $querySource = "SELECT * FROM source_link WHERE `link_month` = '{$month}' AND `project_link` = {$_POST['google_project']}";
        if ($databaseSource->checkRow($querySource) == true) {
            $arrayWhere = array(array('link_month', $month, 'AND'), array('project_link', $_POST['google_project'], null));
            $databaseSource->update($arraySource, $arrayWhere);
            if ($databaseSource->affectedRows() > 0) {
                $message = '<div class="alert alert-success">
								<button class="close" data-dismiss="alert"></button>
								Update successful!
							</div>';
            }
        } else {
            $databaseSource->insert($arraySource, 'single');
            if ($databaseSource->affectedRows() > 0) {
                $message = '<div class="alert alert-success">
								<button class="close" data-dismiss="alert"></button>
								Insert successful!
							</div>';
            }
        }
    }
<?php

require_once 'commandLine.inc';
require_once "{$IP}/extensions/wikihow/titus/Titus.class.php";
$dbw = new Database(TITUS_DB_HOST, WH_DATABASE_MAINTENANCE_USER, WH_DATABASE_MAINTENANCE_PASSWORD, TitusDB::getDBName());
$sql = "delete t.* from " . TitusDB::getDBName() . ".titus_intl t left join " . Misc::getLangDB($wgLanguageCode) . ".page p on ti_page_id = p.page_id WHERE p.page_is_redirect=1 AND ti_language_code='{$wgLanguageCode}'";
$dbw->query($sql);
print $dbw->affectedRows() . " rows deleted in {$wgLanguageCode} ";
Example #6
0
 /**
  * clean
  *
  * @param int $expire Expire
  *
  * @return array
  */
 private function clean($expire)
 {
     $this->dbc->query("DELETE FROM `" . SESSIONS . "`\n            WHERE DATE_ADD(`session_last_accessed`, INTERVAL " . (int) $expire . " SECOND) < NOW()");
     return $this->dbc->affectedRows();
 }
Example #7
0
 /**
  * Return the number of rows affected by the previous operation.
  * @return int
  */
 static function affectedRows()
 {
     return DB::$globalConn->affectedRows();
 }