<?php
/*
* Created on 02.05.2006 by *Camper*
*/
class Form_Deploy extends Form{
function init(){
parent::init();
$this
->addComment("Deploying process will save scripts to the specified directory <br>and change " .
"current version to specified below. <br>Click 'Deploy' to continue")
->addField('line', 'version', 'New version')//->setProperty('value', $this->api->getNextVersion($this->api->recall('application_id')))
->set('version', $this->api->getNextVersion($this->api->recall('application_id')))
->addSubmit('Deploy')
;
}
function submitted(){
if(parent::submitted()){
$this->deploy();
//updating old version dts
$this->api->db->query("update version set deploy_dts=SYSDATE() where id=".$this->api->recall('deploy_id'));
//changing version
$this->api->db->query("insert into version (name, application_id) values('".
$this->get('version')."', ".$this->api->recall('application_id').")");
$this->api->redirect('Application');
}
}
function deploy(){
$id = $this->api->recall('deploy_id');
if(!$id)throw new BaseException("Version to deploy is not defined.");
$dirname = $this->api->db->getOne("select dirname from application a " .
"join version v on v.application_id = a.id where v.id = $id");
$dosvn = $this->api->db->getOne("select svn from application a " .
"join version v on v.application_id = a.id where v.id = $id") == 'Y';
if(substr($dirname, strlen($dirname))!=DIRECTORY_SEPARATOR)$dirname.=DIRECTORY_SEPARATOR;
//deploying
$scripts = $this->api->db->getAllHash("select s.id, s.number, v.name, s.script, s.type from script s " .
"join version v on v.id = s.version_id where v.id = $id");
foreach($scripts as $script){
$filename = $dirname . $script['name'] . "." . $script['number'] . "." . $script['type'];
file_put_contents($filename, $script['script']);
//trying to svn add it
$output = '';
$return = '';
if($dosvn)exec("svn add $filename", $output, $return);
}
}
}