/** * Gets the fields => values to write to the table. * * @since 1.20 * @deprecated since 1.22 * * @return array */ protected function getWriteValues() { $values = array(); foreach ( $this->table->getFields() as $name => $type ) { if ( array_key_exists( $name, $this->fields ) ) { $value = $this->fields[$name]; // Skip null id fields so that the DBMS can set the default. if ( $name === 'id' && is_null ( $value ) ) { continue; } switch ( $type ) { case 'array': $value = (array)$value; // fall-through! case 'blob': $value = serialize( $value ); // fall-through! } $values[$this->table->getPrefixedField( $name )] = $value; } } return $values; }
/** * Add an amount (can be negative) to the specified field (needs to be numeric). * TODO: most off this stuff makes more sense in the table class * * @since 1.20 * * @param string $field * @param integer $amount * * @return boolean Success indicator */ public function addToField($field, $amount) { if ($amount == 0) { return true; } if (!$this->hasIdField()) { return false; } $absoluteAmount = abs($amount); $isNegative = $amount < 0; $dbw = wfGetDB(DB_MASTER); $fullField = $this->table->getPrefixedField($field); $success = $dbw->update($this->table->getName(), array("{$fullField}={$fullField}" . ($isNegative ? '-' : '+') . $absoluteAmount), array($this->table->getPrefixedField('id') => $this->getId()), __METHOD__); if ($success && $this->hasField($field)) { $this->setField($field, $this->getField($field) + $amount); } return $success; }