diff --git a/webinstall/cibuild.php b/webinstall/cibuild.php index 414a400..c17cd00 100644 --- a/webinstall/cibuild.php +++ b/webinstall/cibuild.php @@ -2,8 +2,6 @@ include("token.php"); include("functions.php"); include("config.php"); -mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); -include("cibuild_connection.php"); if (! isset($CI_TOKEN)) die("no token"); const apiBase="https://circleci.com/api/v2/"; const webApp="https://app.circleci.com/"; @@ -95,7 +93,7 @@ function getArtifacts($job,$slug){ } function insertPipeline($id,$param){ - global $database; + $database=openDb(); if (! isset($database)) return false; try { $status='created'; @@ -115,7 +113,7 @@ function insertPipeline($id,$param){ } } function updatePipeline($id,$status,$tag=null){ - global $database; + $database=openDb(); if (! isset($database)) return false; try{ $stmt=null; @@ -139,25 +137,26 @@ function updatePipeline($id,$status,$tag=null){ function findPipeline($param) { - global $database; + $database=openDb(); if (!isset($database)) return false; try { $stmt = null; if (isset($param['tag'])) { - $stmt = $database->prepare("SELECT * from " . TABLENAME . + $stmt = $database->prepare("SELECT id,UNIX_TIMESTAMP(timestamp) from " . TABLENAME . " where status='success' and environment=? and buildflags=? and tag=? order by timestamp desc"); $stmt->bind_param("sss", $param['environment'], $param['buildflags'], $param['tag']); } else { - $stmt = $database->prepare("SELECT id from " . TABLENAME . + $stmt = $database->prepare("SELECT id,UNIX_TIMESTAMP(timestamp) from " . TABLENAME . " where status='success' and environment=? and buildflags=? order by timestamp desc"); $stmt->bind_param("ss", $param['environment'], $param['buildflags']); } $stmt->execute(); $id=null; - $stmt->bind_result($id); + $timestamp=null; + $stmt->bind_result($id,$timestamp); if ($stmt->fetch()){ - return $id; + return array('pipeline'=>$id,'timestamp'=>$timestamp); } return false; } catch (Exception $e) { @@ -295,12 +294,12 @@ try { $par=array(); addVars($par,['environment','buildflags']); if (isset($_REQUEST['tag'])) $par['tag']=$_REQUEST['tag']; - $id=findPipeline($par); + $rt=findPipeline($par); header("Content-Type: application/json"); - $rt=array('status'=>'OK'); - if ($id){ - $rt['pipeline']=$id; + if (!$rt){ + $rt=array(); } + $rt['status']='OK'; echo(json_encode($rt)); exit(0); } diff --git a/webinstall/create_db.php b/webinstall/create_db.php new file mode 100644 index 0000000..a37139d --- /dev/null +++ b/webinstall/create_db.php @@ -0,0 +1,28 @@ +"; +$rt=$database->query($sql); +echo "execute OK
"; +} catch (Exception $e){ + echo "ERROR: ".$e; +} + + +?> \ No newline at end of file diff --git a/webinstall/functions.php b/webinstall/functions.php index d431058..bb27108 100644 --- a/webinstall/functions.php +++ b/webinstall/functions.php @@ -1,4 +1,17 @@ query("SET CHARACTER SET 'utf8'"); + return $db; + }catch (Exception $e){ + error_log("openDB error $e"); + } + return null; +} function safeName($name) { return preg_replace('[^0-9_a-zA-Z.-]', '', $name);