PMA\libraries\Tracker::getVersion PHP Method

getVersion() public static method

Gets the newest version of a tracking job (in other words: gets the HEAD version).
public static getVersion ( string $dbname, string $tablename, string $statement = null ) : integer
$dbname string name of database
$tablename string name of table
$statement string tracked statement
return integer (-1 if no version exists | > 0 if a version exists)
    public static function getVersion($dbname, $tablename, $statement = null)
    {
        $sql_query = " SELECT MAX(version) FROM " . self::_getTrackingTable() . " WHERE `db_name` = '" . $GLOBALS['dbi']->escapeString($dbname) . "' " . " AND `table_name` = '" . $GLOBALS['dbi']->escapeString($tablename) . "' ";
        if ($statement != "") {
            $sql_query .= " AND FIND_IN_SET('" . $statement . "',tracking) > 0";
        }
        $row = $GLOBALS['dbi']->fetchArray(PMA_queryAsControlUser($sql_query));
        return isset($row[0]) ? $row[0] : -1;
    }

Usage Example

Example #1
0
/**
 * Get untracked tables
 *
 * @param string $db current database
 *
 * @return array $untracked_tables
 */
function PMA_getUntrackedTables($db)
{
    $untracked_tables = array();
    $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
    // Get list of tables
    $table_list = PMA\libraries\Util::getTableList($db);
    // For each table try to get the tracking version
    foreach ($table_list as $key => $value) {
        // If $value is a table group.
        if (array_key_exists('is' . $sep . 'group', $value) && $value['is' . $sep . 'group']) {
            foreach ($value as $temp_table) {
                // If $temp_table is a table with the value for 'Name' is set,
                // rather than a property of the table group.
                if (is_array($temp_table) && array_key_exists('Name', $temp_table)) {
                    $tracking_version = Tracker::getVersion($db, $temp_table['Name']);
                    if ($tracking_version == -1) {
                        $untracked_tables[] = $temp_table['Name'];
                    }
                }
            }
        } else {
            // If $value is a table.
            if (Tracker::getVersion($db, $value['Name']) == -1) {
                $untracked_tables[] = $value['Name'];
            }
        }
    }
    return $untracked_tables;
}
All Usage Examples Of PMA\libraries\Tracker::getVersion