Skip to content

Commit

Permalink
Better error reporting for ezdfs handler; clean up dead code and warn…
Browse files Browse the repository at this point in the history
…ings reported by phpstorm
  • Loading branch information
gggeek authored and yannickroger committed Oct 14, 2015
1 parent 72b2331 commit b7b5df4
Showing 1 changed file with 20 additions and 31 deletions.
51 changes: 20 additions & 31 deletions clusterfilehandlers/dfsbackends/oracle.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ private function _copyInner( $srcFilePath, $dstFilePath, $fname, $metaData )
//$nameTrunk = self::nameTrunk( $dstFilePath, $scope );

/// @todo move to stored params convention
$name = $this->_escapeString( $dstFilePath );
$hash = md5( $dstFilePath );
$sql = "INSERT INTO " . self::TABLE_METADATA . " (datatype, name, name_hash, scope, filesize, mtime, expired) " .
"VALUES ('$datatype', '$filePathEscaped', '$filePathHash', '$scope', " .
"$contentLength, $fileMTime, '0')";
Expand Down Expand Up @@ -524,9 +522,9 @@ protected function _deleteByWildcardInner( $wildcard, $fname )
public function _deleteByDirList( $dirList, $commonPath, $commonSuffix, $fname = false )
{
if ( $fname )
$fname .= "::_deleteByDirList($dirList, $commonPath, $commonSuffix)";
$fname .= "::_deleteByDirList(" . implode( ',', $dirList ) . ", $commonPath, $commonSuffix)";
else
$fname = "_deleteByDirList($dirList, $commonPath, $commonSuffix)";
$fname = "_deleteByDirList(" . implode( ',', $dirList ) . ", $commonPath, $commonSuffix)";
return $this->_protect( array( $this, '_deleteByDirListInner' ), $fname,
$dirList, $commonPath, $commonSuffix, $fname );
}
Expand Down Expand Up @@ -787,7 +785,7 @@ public function _rename( $srcFilePath, $dstFilePath )
$srcFilePath, $dstFilePath, $fname, $metaData );
}

function _renameInner( $srcFilePath, $dstFilePath, $fname, $metaData )
protected function _renameInner( $srcFilePath, $dstFilePath, $fname, $metaData )
{
// Delete destination file if exists.
// NOTE: no use in fetching before deleting it...
Expand Down Expand Up @@ -848,7 +846,7 @@ function _store( $filePath, $datatype, $scope, $fname = false )
* @see eZDFSFileHandlerMySQLBackend::_store()
* @return bool
**/
function _storeInner( $filePath, $datatype, $scope, $fname )
protected function _storeInner( $filePath, $datatype, $scope, $fname )
{
// Insert file metadata.
clearstatcache( true, $filePath );
Expand Down Expand Up @@ -998,7 +996,7 @@ function _storeContents( $filePath, $contents, $scope, $datatype, $mtime = false
$filePath, $contents, $scope, $datatype, $mtime, $fname );
}

function _storeContentsInner( $filePath, $contents, $scope, $datatype, $mtime, $fname )
protected function _storeContentsInner( $filePath, $contents, $scope, $datatype, $mtime, $fname )
{
// Mostly cut&pasted from _store().
if ( $fname )
Expand Down Expand Up @@ -1196,10 +1194,6 @@ protected function _selectOne( $query, $fname, $error = false, $debug = false, $
**/
protected function _begin( $fname = false )
{
if ( $fname )
$fname .= "::_begin";
else
$fname = "_begin";
$this->transactionCount++;
/// @todo set savepoint
}
Expand All @@ -1210,10 +1204,6 @@ protected function _begin( $fname = false )
**/
protected function _commit( $fname = false )
{
if ( $fname )
$fname .= "::_commit";
else
$fname = "_commit";
$this->transactionCount--;
if ( $this->transactionCount == 0 )
oci_commit( $this->db );
Expand All @@ -1226,10 +1216,6 @@ protected function _commit( $fname = false )
**/
protected function _rollback( $fname = false )
{
if ( $fname )
$fname .= "::_rollback";
else
$fname = "_rollback";
$this->transactionCount--;
if ( $this->transactionCount == 0 )
oci_rollback( $this->db );
Expand Down Expand Up @@ -1354,7 +1340,8 @@ protected function _query( $query, $fname = false, $reportError = true, $bindpar
if ( !oci_bind_by_name( $statement, $name, $bindparams[$name], -1 ) )
{
$this->error = oci_error( $statement );
$this->_error( $query, $fname, $this->error );
// binding errors we always report, regardless of $reportError
$this->_error( $query, $fname, "Failed to bind parameter '$name'" );
}
}
}
Expand All @@ -1367,7 +1354,8 @@ protected function _query( $query, $fname = false, $reportError = true, $bindpar
{
$commitMode = OCI_DEFAULT;
}
if ( ! $res = oci_execute( $statement, $commitMode ) )
// swallow oci warnings, as we report them only if caller asks for it
if ( ! $res = @oci_execute( $statement, $commitMode ) )
{
$this->error = oci_error( $statement );
}
Expand All @@ -1388,16 +1376,18 @@ protected function _query( $query, $fname = false, $reportError = true, $bindpar
}

oci_free_statement( $statement );

// take care: 0 might be a valid result if RETURN_COUNT is used
if ( $res === false && $reportError )
{
$this->_error( $query, $fname, false );
}
}
else
{
$this->error = oci_error( $this->db );
}

// take care: 0 might be a valid result if RETURN_COUNT is used
if ( $res === false && $reportError )
{
$this->_error( $query, $fname, false, $this->error );
// parsing errors we always report, regardless of $reportError
$this->_error( $query, $fname, "Failed to parse query" );
}

$time = microtime( true ) - $time;
Expand Down Expand Up @@ -1538,7 +1528,7 @@ public function _startCacheGeneration( $filePath, $generatingFilePath )
// report affected rows
//$stmt = oci_parse( $this->db, $updateQuery );
//$res = oci_execute( $stmt );
$res = $this->_queryAndCommit( $updateQuery, $fname, false, array(), self::RETURN_COUNT );
$res = $this->_queryAndCommit( $updateQuery, $fname, true, array(), self::RETURN_COUNT );
if ( $res === 1 )
{
return array( 'result' => 'ok', 'mtime' => $mtime );
Expand Down Expand Up @@ -1650,14 +1640,13 @@ public function _checkCacheGenerationTimeout( $generatingFilePath, $generatingFi

// reporting
eZDebug::accumulatorStart( 'oracle_cluster_query', 'oracle_cluster_total', 'Oracle_cluster_queries' );
$time = microtime( true );

$nameHash = "'" . md5( $generatingFilePath ) . "'";
$newMtime = time();

// The update query will only succeed if the mtime wasn't changed in between
$query = "UPDATE " . self::TABLE_METADATA . " SET mtime = $newMtime WHERE name_hash = $nameHash AND mtime = $generatingFileMtime";
$numRows = $this->_queryAndCommit( $query, $fname, false, array(), self::RETURN_COUNT );
$numRows = $this->_queryAndCommit( $query, $fname, true, array(), self::RETURN_COUNT );
if ( $numRows === false )
{
/// @todo Throw an exception
Expand Down Expand Up @@ -1848,7 +1837,6 @@ protected function _dfspurgeInner( $array, $dryRun = false, $printCallback = fal

/**
* DB connection handle
* @var handle
**/
public $db = null;

Expand Down Expand Up @@ -1896,6 +1884,7 @@ protected function _dfspurgeInner( $array, $dryRun = false, $printCallback = fal
//static $deletequery = "UPDATE ezdbfile SET mtime=-ABS(mtime), expired='1' ";
static $deletequery = "DELETE FROM ezdfsfile ";

protected $error;
}

?>

0 comments on commit b7b5df4

Please sign in to comment.