Model.class.php
public function save( $propvalues = null, $reserved = false )
	{

		$dbr = wfGetDB( DB_MASTER );
		$dbr->begin();

		$sourceprops = $this->properties;
		$insertId = null;

		foreach ( $sourceprops as $prop => $type ) {
			$sourceprops[$prop] = (isset($this->values[$prop])) ? $this->values[$prop] : '';
		}

		/* New values from passed $propvalues array  */
		if ( $propvalues != null && is_array( $propvalues ) ) {

			if ( array_key_exists( 'id', $propvalues ) )
				throw new Exception('ORM.Model: `id` parameter cant be passed in poperties array.');

			foreach ( $propvalues as $prop => $value ) {
				if ( isset($this->properties[$prop]) ) $sourceprops[$prop] = $value;
			}
		}

		$sourceprops['id'] = $this->id;

		if ( $this->isNew ) {

			/* New entity */
			$dbr->insert( static::$table,
				$sourceprops,
				__METHOD__
			);

			$insertId = $dbr->insertId();

		} else {

			/* Check id, just for sure */
			if ( !is_numeric( $this->id ) ) throw new Exception('WikivoteVoting: There is no `id` field on exesting entity update. Fatal error.');

			/* Update existing entity */
			$dbr->update( static::$table,
				$sourceprops,
				array( 'id' => $this->id ),
				__METHOD__
			);

			$insertId = $this->id;

		}

		$dbr->commit();

		return $insertId;

	}
public function save( $propvalues = null, $reserved = false )
	{

		$dbr = wfGetDB( DB_MASTER );
		$dbr->begin();

		$sourceprops = $this->properties;
		$insertId = null;

		foreach ( $sourceprops as $prop => $type ) {
			$sourceprops[$prop] = (isset($this->values[$prop])) ? $this->values[$prop] : '';
		}

		/* New values from passed $propvalues array  */
		if ( $propvalues != null && is_array( $propvalues ) ) {

			if ( array_key_exists( 'id', $propvalues ) )
				throw new Exception('ORM.Model: `id` parameter cant be passed in poperties array.');

			foreach ( $propvalues as $prop => $value ) {
				if ( isset($this->properties[$prop]) ) $sourceprops[$prop] = $value;
			}
		}

		$sourceprops['id'] = $this->id;

		if ( $this->isNew ) {

			/* New entity */
			$dbr->insert( static::$table,
				$sourceprops,
				__METHOD__
			);

			$insertId = $dbr->insertId();

		} else {

			/* Check id, just for sure */
			if ( !is_numeric( $this->id ) ) throw new Exception('WikivoteVoting: There is no `id` field on exesting entity update. Fatal error.');

			/* Update existing entity */
			$dbr->update( static::$table,
				$sourceprops,
				array( 'id' => $this->id ),
				__METHOD__
			);

			$insertId = $this->id;

		}

		$dbr->commit();

		return $insertId;

	}
public function save ( $ propvalues = null , $ reserved = false ) { $ dbr = wfGetDB ( DB_MASTER ) ; $ dbr -> begin ( ) ; $ sourceprops = $ this -> properties ; $ insertId = null ; foreach ( $ sourceprops as $ prop => $ type ) { $ sourceprops [ $ prop ] = ( isset ( $ this -> values [ $ prop ] ) ) ? $ this -> values [ $ prop ] : '' ; } /* New values from passed $propvalues array  */ if ( $ propvalues != null && is_array ( $ propvalues ) ) { if ( array_key_exists ( 'id' , $ propvalues ) ) throw new Exception ( 'ORM.Model: `id` parameter cant be passed in poperties array.' ) ; foreach ( $ propvalues as $ prop => $ value ) { if ( isset ( $ this -> properties [ $ prop ] ) ) $ sourceprops [ $ prop ] = $ value ; } } $ sourceprops [ 'id' ] = $ this -> id ; if ( $ this -> isNew ) { /* New entity */ $ dbr -> insert ( static :: $ table , $ sourceprops , __METHOD__ ) ; $ insertId = $ dbr -> insertId ( ) ; } else { /* Check id, just for sure */ if ( ! is_numeric ( $ this -> id ) ) throw new Exception ( 'WikivoteVoting: There is no `id` field on exesting entity update. Fatal error.' ) ; /* Update existing entity */ $ dbr -> update ( static :: $ table , $ sourceprops , array ( 'id' => $ this -> id ) , __METHOD__ ) ; $ insertId = $ this -> id ; } $ dbr -> commit ( ) ; return $ insertId ; }
Save entity instance in database.
@param null $propvalues
@param bool $reserved
@return int
@throws Exception
Save entity instance in database .