Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
0b479ff5
Commit
0b479ff5
authored
8 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
#1385 - first basic code for a version class; cache is a sqlite table
parent
4869a92e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
public_html/versions/classes/versions.class.php
+190
-0
190 additions, 0 deletions
public_html/versions/classes/versions.class.php
public_html/versions/index.php
+26
-0
26 additions, 0 deletions
public_html/versions/index.php
with
216 additions
and
0 deletions
public_html/versions/classes/versions.class.php
0 → 100644
+
190
−
0
View file @
0b479ff5
<?php
/**
* version data handler for the deployment tool
*
* @author hahn
*/
class
versions
{
//put your code here
public
$sProject
=
false
;
public
$sPhase
=
false
;
public
$sPlace
=
false
;
public
$sVariable
=
false
;
public
$sData
=
false
;
/**
* filename of
* @var type
*/
private
$_dbfile
=
false
;
private
$_sCreate
=
'
CREATE TABLE "versions" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
`time` DATETIME,
`project` TEXT,
`phase` TEXT,
`place` TEXT,
`host` TEXT,
`variable` TEXT,
`data` TEXT,
UNIQUE (project, phase, place, host, variable) ON CONFLICT REPLACE
);'
;
// ----------------------------------------------------------------------
// CONSTRUCTOR
// ----------------------------------------------------------------------
public
function
__construct
(){
// cache dir is hardcoded to versions directory :-/
$this
->
_dbfile
=
__DIR__
.
'/../data/versioncache.db'
;
if
(
!
file_exists
(
$this
->
_dbfile
))
{
$this
->
_createDb
();
if
(
!
file_exists
(
$this
->
_dbfile
))
{
die
(
"ERROR: unable to create sqlite database "
.
$this
->
_dbfile
);
}
}
}
// ----------------------------------------------------------------------
// PRIVATE
// ----------------------------------------------------------------------
/**
* create sqlite database - called in constructor if the file does not exist
*/
private
function
_createDb
()
{
echo
"try to create file
$this->_dbfile
...<br>
\n
"
;
return
$this
->
_makeQuery
(
$this
->
_sCreate
);
}
/**
* execute a sql statement
* @param string $sSql sql statement
* @return database object
*/
private
function
_makeQuery
(
$sSql
)
{
// $this->_log(__FUNCTION__."($sSql)");
echo
"DEBUG: executing SQL<pre>
$sSql
</pre>"
;
$db
=
new
PDO
(
"sqlite:"
.
$this
->
_dbfile
);
$result
=
$db
->
query
(
$sSql
);
$db
=
NULL
;
return
$result
;
}
// ----------------------------------------------------------------------
// PUBLIC GETTER
// ----------------------------------------------------------------------
public
function
getVersion
(){
if
(
!
$this
->
sProject
||
!
$this
->
sPhase
||
!
$this
->
sPlace
){
die
(
"ERROR: you need to set a project, phase and place. use the setProject() method to do so."
);
}
$aReturn
=
array
();
$sSql
=
"select * from `versions`
WHERE
project='"
.
$this
->
sProject
.
"'
AND phase='"
.
$this
->
sPhase
.
"'
AND place='"
.
$this
->
sPlace
.
"'
AND host='"
.
$this
->
sHost
.
"'
"
;
foreach
(
$this
->
_makeQuery
(
$sSql
)
as
$row
)
{
for
(
$i
=
0
;
$i
<=
count
(
$row
);
$i
++
)
{
unset
(
$row
[
$i
]);
}
$aReturn
[]
=
$row
;
}
return
$aReturn
;
}
public
function
whereiam
(){
return
array
(
'project'
=>
$this
->
sProject
,
'phase'
=>
$this
->
sPhase
,
'place'
=>
$this
->
sPlace
,
'host'
=>
$this
->
sHost
,
);
}
// ----------------------------------------------------------------------
// PUBLIC SETTER
// ----------------------------------------------------------------------
public
function
setProject
(
$sProject
,
$sPhase
=
false
,
$sPlace
=
false
,
$sHost
=
false
){
$this
->
sProject
=
$sProject
;
$this
->
setPhase
(
$sPhase
,
$sPlace
,
$sHost
);
return
$this
->
sProject
;
}
public
function
setPhase
(
$sPhase
,
$sPlace
=
false
,
$sHost
=
false
){
if
(
!
$this
->
sProject
){
die
(
"ERROR: you need to set a project. Use the setProject() method to do so."
);
return
false
;
}
$this
->
sPhase
=
$sPhase
;
$this
->
setPlace
(
$sPlace
,
$sHost
);
return
$this
->
sPhase
;
}
public
function
setPlace
(
$sPlace
,
$sHost
=
false
){
if
(
!
$this
->
sProject
||
!
$this
->
sPhase
){
die
(
"ERROR: you need to set a project and phase. Use the setProject() method to do so."
);
return
false
;
}
if
(
$sPlace
!==
'queue'
&&
$sPlace
!==
'puppet'
&&
$sPlace
!==
'installed'
){
die
(
"ERROR: you set a wrong place [
$sPlace
]"
);
}
$this
->
sPlace
=
$sPlace
;
$this
->
setHost
(
$sHost
);
return
$this
->
sPlace
;
}
public
function
setHost
(
$sHost
=
false
){
if
(
!
$this
->
sProject
||
!
$this
->
sPhase
||
!
$this
->
sPlace
){
die
(
"ERROR: you need to set a project, phase and place. Use the setProject() method to do so."
);
return
false
;
}
if
(
$sHost
&&
$this
->
sPlace
!==
'installed'
){
die
(
"ERROR: a host can be set on place [installed] only."
);
}
if
(
!
$sHost
&&
$this
->
sPlace
===
'installed'
){
die
(
"ERROR: on place [installed] a host MUST be set."
);
}
$this
->
sHost
=
$sHost
;
return
$this
->
sHost
;
}
/**
* update a version
* @return boolean
*/
public
function
updateVersion
(
$sVersioninfos
){
if
(
!
$this
->
sProject
||
!
$this
->
sPhase
||
!
$this
->
sPlace
){
die
(
"ERROR: you need to set a project, phase and place. use the setProject() method to do so."
);
}
$sSql
=
"
INSERT into `versions`
(`time`, `project`, `phase`, `place`, `host`, `variable`, `data` )
VALUES
(
'"
.
date
(
"Y-m-d H:i:s"
)
.
"',
'"
.
$this
->
sProject
.
"',
'"
.
$this
->
sPhase
.
"',
'"
.
$this
->
sPlace
.
"',
'"
.
$this
->
sHost
.
"',
'version',
'"
.
$sVersioninfos
.
"'
);
"
;
return
$this
->
_makeQuery
(
$sSql
);
}
}
This diff is collapsed.
Click to expand it.
public_html/versions/index.php
0 → 100644
+
26
−
0
View file @
0b479ff5
<?php
echo
'<pre>'
.
print_r
(
$_GET
,
1
)
.
'</pre>'
;
require
'./classes/versions.class.php'
;
$oVersion
=
new
versions
();
$sProject
=
'ci'
;
$sPhase
=
'preview'
;
$sPlace
=
'installed'
;
$sHost
=
'preview02.ci'
;
$oVersion
->
setProject
(
$sProject
,
$sPhase
,
$sPlace
,
$sHost
);
print_r
(
$oVersion
->
whereiam
());
/*
if ($oVersion->updateVersion('{ "revision": "000" }')){
print_r($oVersion->getVersion());
} else {
echo "insert failed. :-(";
}
*/
print_r
(
$oVersion
->
getVersion
());
// $oVersion->
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment