Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Simple admin action to check if a table exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Mar 29, 2016
1 parent 0687994 commit 5b9615e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/src/plugins/conf.sql/class.sqlConfDriver.php
Expand Up @@ -1253,4 +1253,23 @@ public function userTeamsActions($actionName, $httpVars, $fileVars)
}
}


public function ajxpTableExists($actionName, $httpVars, $fileVars){

$p = $this->sqlDriver;
if($p["driver"] == "postgre"){
$tableQuery = "SELECT [tablename] FROM [pg_catalog].[pg_tables] WHERE [tablename] = %s";
}else if($p["driver"] == "sqlite3" || $p["driver"] == "sqlite"){
$tableQuery = "SELECT [name] FROM [sqlite_master] WHERE type = \"table\" AND [name] = %s";
}else{
$tableQuery = "SHOW TABLES LIKE %s";
}
$tableName = AJXP_Utils::sanitize($httpVars["table_name"], AJXP_SANITIZE_ALPHANUM);
$tables = dibi::query($tableQuery, $tableName)->fetchPairs();
$exists = (count($tables) && in_array($tableName, $tables));
HTMLWriter::charsetHeader("application/json");
echo json_encode(array("result" => $exists));

}

}
6 changes: 6 additions & 0 deletions core/src/plugins/conf.sql/manifest.xml
Expand Up @@ -110,6 +110,12 @@
<serverCallback methodName="userTeamsActions"/>
</processing>
</action>
<action name="ajxp_table_exists">
<rightsContext adminOnly="true" noUser="false" read="true" userLogged="only" write="true"/>
<processing>
<serverCallback methodName="ajxpTableExists" restParams="/table_name"/>
</processing>
</action>
</actions>
<client_configs>
<component_config className="AjxpTabulator::userdashboard_main_tab">
Expand Down

0 comments on commit 5b9615e

Please sign in to comment.