Code Duplication    Length = 14-14 lines in 3 locations

includes/db/DatabaseMysqlBase.php 2 locations

@@ 969-982 (lines=14) @@
966
	 * @param int $timeout
967
	 * @return bool
968
	 */
969
	public function lock( $lockName, $method, $timeout = 5 ) {
970
		$lockName = $this->addQuotes( $this->makeLockName( $lockName ) );
971
		$result = $this->query( "SELECT GET_LOCK($lockName, $timeout) AS lockstatus", $method );
972
		$row = $this->fetchObject( $result );
973
974
		if ( $row->lockstatus == 1 ) {
975
			parent::lock( $lockName, $method, $timeout ); // record
976
			return true;
977
		}
978
979
		wfDebug( __METHOD__ . " failed to acquire lock\n" );
980
981
		return false;
982
	}
983
984
	/**
985
	 * FROM MYSQL DOCS:
@@ 991-1004 (lines=14) @@
988
	 * @param string $method
989
	 * @return bool
990
	 */
991
	public function unlock( $lockName, $method ) {
992
		$lockName = $this->addQuotes( $this->makeLockName( $lockName ) );
993
		$result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method );
994
		$row = $this->fetchObject( $result );
995
996
		if ( $row->lockstatus == 1 ) {
997
			parent::unlock( $lockName, $method ); // record
998
			return true;
999
		}
1000
1001
		wfDebug( __METHOD__ . " failed to release lock\n" );
1002
1003
		return false;
1004
	}
1005
1006
	private function makeLockName( $lockName ) {
1007
		// http://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html#function_get-lock

includes/db/DatabasePostgres.php 1 location

@@ 1615-1628 (lines=14) @@
1612
	 * @param string $method
1613
	 * @return bool
1614
	 */
1615
	public function unlock( $lockName, $method ) {
1616
		$key = $this->addQuotes( $this->bigintFromLockName( $lockName ) );
1617
		$result = $this->query( "SELECT pg_advisory_unlock($key) as lockstatus", $method );
1618
		$row = $this->fetchObject( $result );
1619
1620
		if ( $row->lockstatus === 't' ) {
1621
			parent::unlock( $lockName, $method ); // record
1622
			return true;
1623
		}
1624
1625
		wfDebug( __METHOD__ . " failed to release lock\n" );
1626
1627
		return false;
1628
	}
1629
1630
	/**
1631
	 * @param string $lockName