src/Awjudd/Revisable/Revisable.php
public static function removeExpired(array $where = array())
    {
        // Check if we either have no revisions enabled, or it is set to infinite
        if(static::$revisionCount <= 0)
        {
            // Remove nothing
            return TRUE;
        }

        // Otherwise look for the expired revisions
        if( static::hasAlternateRevisionTable())
        {
            $query = \DB::table(static::$revisionTable);
        }
        else
        {
            $query = self::onlyTrashed();
        }

        // Were there any where clause filters?
        if(count($where)>0)
        {
            // There were, so add them in
            foreach($where as $key => $value)
            {
                $query->where($key, '=', $value);
            }
        }

        // Were there any columns that were defined as a "key column"
        if(count(static::$keyColumns) > 0)
        {
            // There were, so add in the group bys
            foreach(static::$keyColumns as $column)
            {
                $query->groupBy($column);
            }

            // Send back all of the key columns where we have more than the allowed
            $query->having(\DB::raw('count(1)'), '>', static::$revisionCount)
                ->addSelect(static::$keyColumns);
        }
        else
        {
            $query->where(\DB::raw('count(1)'), '>', static::$revisionCount);
        }

        // List of all of the ids affected by the revision count
        $ids = array();

        // Cycle through the list
        foreach($query->get() as $row)
        {
            // Otherwise look for the expired revisions
            if(static::hasAlternateRevisionTable())
            {
                $filter = \DB::table(static::$revisionTable);
            }
            else
            {
                $filter = self::onlyTrashed();
            }

            //
            foreach(static::$keyColumns as $column)
            {
                $filter->where($column, '=', $row->$column);
            }

            $filter->skip(static::$revisionCount)

                // Take as many as we need
                ->take(PHP_INT_MAX)

                // Grab anything that was soft deleted after the number we keep
                ->orderBy('created_at', 'desc')

                // Grab the ID column
                ->addSelect('id');

            // Cycle through all of the records
            foreach($filter->get() as $id)
            {
                $ids[] = $id->id;
            }
        }

        // Were there any records that fit the criteria
        if(count($ids) > 0)
        {
            // There were, so 
            if(static::hasAlternateRevisionTable())
            {
                $delete = \DB::table(static::$revisionTable);
            }
            else
            {
                $delete = self::onlyTrashed();
            }

            // Filter all of the selected
            $delete->whereIn('id', $ids);

            // Figure out how we should delete
            if(static::hasAlternateRevisionTable())
            {
                // Alternate table, so just delete it
                $delete->delete();
            }
            else
            {
                // Otherwise delete it
                $delete->forceDelete();
            }
        }

        return TRUE;
    }
public static function removeExpired(array $where = array())
    {
        // Check if we either have no revisions enabled, or it is set to infinite
        if(static::$revisionCount <= 0)
        {
            // Remove nothing
            return TRUE;
        }

        // Otherwise look for the expired revisions
        if( static::hasAlternateRevisionTable())
        {
            $query = \DB::table(static::$revisionTable);
        }
        else
        {
            $query = self::onlyTrashed();
        }

        // Were there any where clause filters?
        if(count($where)>0)
        {
            // There were, so add them in
            foreach($where as $key => $value)
            {
                $query->where($key, '=', $value);
            }
        }

        // Were there any columns that were defined as a "key column"
        if(count(static::$keyColumns) > 0)
        {
            // There were, so add in the group bys
            foreach(static::$keyColumns as $column)
            {
                $query->groupBy($column);
            }

            // Send back all of the key columns where we have more than the allowed
            $query->having(\DB::raw('count(1)'), '>', static::$revisionCount)
                ->addSelect(static::$keyColumns);
        }
        else
        {
            $query->where(\DB::raw('count(1)'), '>', static::$revisionCount);
        }

        // List of all of the ids affected by the revision count
        $ids = array();

        // Cycle through the list
        foreach($query->get() as $row)
        {
            // Otherwise look for the expired revisions
            if(static::hasAlternateRevisionTable())
            {
                $filter = \DB::table(static::$revisionTable);
            }
            else
            {
                $filter = self::onlyTrashed();
            }

            //
            foreach(static::$keyColumns as $column)
            {
                $filter->where($column, '=', $row->$column);
            }

            $filter->skip(static::$revisionCount)

                // Take as many as we need
                ->take(PHP_INT_MAX)

                // Grab anything that was soft deleted after the number we keep
                ->orderBy('created_at', 'desc')

                // Grab the ID column
                ->addSelect('id');

            // Cycle through all of the records
            foreach($filter->get() as $id)
            {
                $ids[] = $id->id;
            }
        }

        // Were there any records that fit the criteria
        if(count($ids) > 0)
        {
            // There were, so 
            if(static::hasAlternateRevisionTable())
            {
                $delete = \DB::table(static::$revisionTable);
            }
            else
            {
                $delete = self::onlyTrashed();
            }

            // Filter all of the selected
            $delete->whereIn('id', $ids);

            // Figure out how we should delete
            if(static::hasAlternateRevisionTable())
            {
                // Alternate table, so just delete it
                $delete->delete();
            }
            else
            {
                // Otherwise delete it
                $delete->forceDelete();
            }
        }

        return TRUE;
    }
public static function removeExpired ( array $ where = array ( ) ) { // Check if we either have no revisions enabled, or it is set to infinite if ( static :: $ revisionCount <= 0 ) { // Remove nothing return TRUE ; } // Otherwise look for the expired revisions if ( static :: hasAlternateRevisionTable ( ) ) { $ query = \ DB :: table ( static :: $ revisionTable ) ; } else { $ query = self :: onlyTrashed ( ) ; } // Were there any where clause filters? if ( count ( $ where ) > 0 ) { // There were, so add them in foreach ( $ where as $ key => $ value ) { $ query -> where ( $ key , '=' , $ value ) ; } } // Were there any columns that were defined as a "key column" if ( count ( static :: $ keyColumns ) > 0 ) { // There were, so add in the group bys foreach ( static :: $ keyColumns as $ column ) { $ query -> groupBy ( $ column ) ; } // Send back all of the key columns where we have more than the allowed $ query -> having ( \ DB :: raw ( 'count(1)' ) , '>' , static :: $ revisionCount ) -> addSelect ( static :: $ keyColumns ) ; } else { $ query -> where ( \ DB :: raw ( 'count(1)' ) , '>' , static :: $ revisionCount ) ; } // List of all of the ids affected by the revision count $ ids = array ( ) ; // Cycle through the list foreach ( $ query -> get ( ) as $ row ) { // Otherwise look for the expired revisions if ( static :: hasAlternateRevisionTable ( ) ) { $ filter = \ DB :: table ( static :: $ revisionTable ) ; } else { $ filter = self :: onlyTrashed ( ) ; } // foreach ( static :: $ keyColumns as $ column ) { $ filter -> where ( $ column , '=' , $ row -> $ column ) ; } $ filter -> skip ( static :: $ revisionCount ) // Take as many as we need -> take ( PHP_INT_MAX ) // Grab anything that was soft deleted after the number we keep -> orderBy ( 'created_at' , 'desc' ) // Grab the ID column -> addSelect ( 'id' ) ; // Cycle through all of the records foreach ( $ filter -> get ( ) as $ id ) { $ ids [ ] = $ id -> id ; } } // Were there any records that fit the criteria if ( count ( $ ids ) > 0 ) { // There were, so  if ( static :: hasAlternateRevisionTable ( ) ) { $ delete = \ DB :: table ( static :: $ revisionTable ) ; } else { $ delete = self :: onlyTrashed ( ) ; } // Filter all of the selected $ delete -> whereIn ( 'id' , $ ids ) ; // Figure out how we should delete if ( static :: hasAlternateRevisionTable ( ) ) { // Alternate table, so just delete it $ delete -> delete ( ) ; } else { // Otherwise delete it $ delete -> forceDelete ( ) ; } } return TRUE ; }
Used in order to get rid of any expired revisions.

@param array $where Any filters to apply to the filters
@return boolean
Used in order to get rid of any expired revisions .