clustering/dfs/ezpostsgresqlbackend.php
public function _purgeByLike( $like, $onlyExpired = false, $limit = 50, $expiry = false, $fname = false )
    {
        if ( $fname )
            $fname .= "::_purgeByLike($like, $onlyExpired)";
        else
            $fname = "_purgeByLike($like, $onlyExpired)";

        // common query part used for both DELETE and SELECT
        $where = " WHERE name LIKE " . $this->_quote( $like );

        if ( $expiry !== false )
            $where .= " AND mtime < " . (int)$expiry;
        elseif ( $onlyExpired )
            $where .= " AND expired = 1";

        if ( $limit )
            $sqlLimit = " LIMIT $limit";
        else
            $sqlLimit = "";

        $this->_begin( $fname );

        // select query, in FOR UPDATE mode
        $selectSQL = "SELECT name FROM " . $this->dbTable( $like ) .
                     "{$where} {$sqlLimit} FOR UPDATE";
        if ( !$stmt = $this->_query( $selectSQL, $fname ) )
        {
            $this->_rollback( $fname );
            $this->_fail( "Selecting file metadata by like statement $like failed" );
        }

        $files = array();
        // if there are no results, we can just return 0 and stop right here
        if ( $stmt->rowCount() == 0 )
        {
            $this->_rollback( $fname );
            return 0;
        }
        // the candidate for purge are indexed in an array
        else
        {
            while( $row = $stmt->fetch( PDO::FETCH_ASSOC ) )
            {
                $files[] = $row['name'];
            }
        }

        // delete query
        $deleteSQL = "DELETE FROM " . $this->dbTable( $like ) . " WHERE name_hash IN " .
                     "(SELECT name_hash FROM ". $this->dbTable( $like ) . " $where $sqlLimit)";
        if ( !$stmt = $this->_query( $deleteSQL, $fname ) )
        {
            $this->_rollback( $fname );
            $this->_fail( "Purging file metadata by like statement $like failed" );
        }
        $deletedDBFiles = $stmt->rowCount();
        $this->dfsbackend->delete( $files );

        $this->_commit( $fname );

        return $deletedDBFiles;
    }
public function _purgeByLike( $like, $onlyExpired = false, $limit = 50, $expiry = false, $fname = false )
    {
        if ( $fname )
            $fname .= "::_purgeByLike($like, $onlyExpired)";
        else
            $fname = "_purgeByLike($like, $onlyExpired)";

        // common query part used for both DELETE and SELECT
        $where = " WHERE name LIKE " . $this->_quote( $like );

        if ( $expiry !== false )
            $where .= " AND mtime < " . (int)$expiry;
        elseif ( $onlyExpired )
            $where .= " AND expired = 1";

        if ( $limit )
            $sqlLimit = " LIMIT $limit";
        else
            $sqlLimit = "";

        $this->_begin( $fname );

        // select query, in FOR UPDATE mode
        $selectSQL = "SELECT name FROM " . $this->dbTable( $like ) .
                     "{$where} {$sqlLimit} FOR UPDATE";
        if ( !$stmt = $this->_query( $selectSQL, $fname ) )
        {
            $this->_rollback( $fname );
            $this->_fail( "Selecting file metadata by like statement $like failed" );
        }

        $files = array();
        // if there are no results, we can just return 0 and stop right here
        if ( $stmt->rowCount() == 0 )
        {
            $this->_rollback( $fname );
            return 0;
        }
        // the candidate for purge are indexed in an array
        else
        {
            while( $row = $stmt->fetch( PDO::FETCH_ASSOC ) )
            {
                $files[] = $row['name'];
            }
        }

        // delete query
        $deleteSQL = "DELETE FROM " . $this->dbTable( $like ) . " WHERE name_hash IN " .
                     "(SELECT name_hash FROM ". $this->dbTable( $like ) . " $where $sqlLimit)";
        if ( !$stmt = $this->_query( $deleteSQL, $fname ) )
        {
            $this->_rollback( $fname );
            $this->_fail( "Purging file metadata by like statement $like failed" );
        }
        $deletedDBFiles = $stmt->rowCount();
        $this->dfsbackend->delete( $files );

        $this->_commit( $fname );

        return $deletedDBFiles;
    }
public function _purgeByLike ( $ like , $ onlyExpired = false , $ limit = 50 , $ expiry = false , $ fname = false ) { if ( $ fname ) $ fname .= "::_purgeByLike($like, $onlyExpired)" ; else $ fname = "_purgeByLike($like, $onlyExpired)" ; // common query part used for both DELETE and SELECT $ where = " WHERE name LIKE " . $ this -> _quote ( $ like ) ; if ( $ expiry !== false ) $ where .= " AND mtime < " . ( int ) $ expiry ; elseif ( $ onlyExpired ) $ where .= " AND expired = 1" ; if ( $ limit ) $ sqlLimit = " LIMIT $limit" ; else $ sqlLimit = "" ; $ this -> _begin ( $ fname ) ; // select query, in FOR UPDATE mode $ selectSQL = "SELECT name FROM " . $ this -> dbTable ( $ like ) . "{$where} {$sqlLimit} FOR UPDATE" ; if ( ! $ stmt = $ this -> _query ( $ selectSQL , $ fname ) ) { $ this -> _rollback ( $ fname ) ; $ this -> _fail ( "Selecting file metadata by like statement $like failed" ) ; } $ files = array ( ) ; // if there are no results, we can just return 0 and stop right here if ( $ stmt -> rowCount ( ) == 0 ) { $ this -> _rollback ( $ fname ) ; return 0 ; } // the candidate for purge are indexed in an array else { while ( $ row = $ stmt -> fetch ( PDO :: FETCH_ASSOC ) ) { $ files [ ] = $ row [ 'name' ] ; } } // delete query $ deleteSQL = "DELETE FROM " . $ this -> dbTable ( $ like ) . " WHERE name_hash IN " . "(SELECT name_hash FROM " . $ this -> dbTable ( $ like ) . " $where $sqlLimit)" ; if ( ! $ stmt = $ this -> _query ( $ deleteSQL , $ fname ) ) { $ this -> _rollback ( $ fname ) ; $ this -> _fail ( "Purging file metadata by like statement $like failed" ) ; } $ deletedDBFiles = $ stmt -> rowCount ( ) ; $ this -> dfsbackend -> delete ( $ files ) ; $ this -> _commit ( $ fname ) ; return $ deletedDBFiles ; }
Purges meta-data and file-data for files matching a pattern using a SQL
LIKE syntax.
This method should also remove the files from disk

@see eZDFSFileHandler::purge
@see _purge

@param string $like
SQL LIKE string applied to ezdfsfile.name to look for files to
purge
@param bool $onlyExpired
Only purge expired files (ezdfsfile.expired = 1)
@param integer $limit Maximum number of items to purge in one call
@param integer|bool $expiry
Timestamp used to limit deleted files: only files older than this
date will be deleted
@param bool|string $fname Optional caller name for debugging

@return bool|int false if it fails, number of affected rows otherwise
Purges meta - data and file - data for files matching a pattern using a SQL LIKE syntax . This method should also remove the files from disk