1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/limesurvey_ynh.git synced 2024-09-03 19:36:32 +02:00
limesurvey_ynh/patches/app-0001-7ca4932.patch
2017-02-06 23:40:55 +01:00

106 lines
4.9 KiB
Diff

From 7ca49326dafe4d9896e67aebe414edcd3ce8c1af Mon Sep 17 00:00:00 2001
From: Denis Chenu <denis@sondages.pro>
Date: Thu, 19 Jan 2017 00:02:45 +0100
Subject: [PATCH] [feature] Allow update via PHP cli
---
application/commands/UpdateCommand.php | 90 ++++++++++++++++++++++++++++++++++
1 files changed, 90 insertions(+)
create mode 100644 application/commands/UpdateCommand.php
diff --git a/application/commands/UpdateCommand.php b/application/commands/UpdateCommand.php
new file mode 100644
index 0000000..41ef107
--- /dev/null
+++ b/application/commands/UpdateCommand.php
@@ -0,0 +1,90 @@
+<?php
+ /*
+ * @author Denis Chenu <denis@sondages.pro>
+ * @license GPL v3
+ * @version 0.1
+ *
+ * Copyright (C) 2017 Denis Chenu
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+class UpdateCommand extends CConsoleCommand
+{
+ public function run(){
+ $this->_setConfigs();
+ $newDbVersion = (float)Yii::app()->getConfig('dbversionnumber');
+ $currentDbVersion = (float)Yii::app()->getConfig('DBVersion');
+ if($newDbVersion > $currentDbVersion){
+ echo "Update ".Yii::app()->db->connectionString.", prefix :".Yii::app()->db->tablePrefix." from {$currentDbVersion} to {$newDbVersion}\n";
+ Yii::import('application.helpers.common_helper', true);
+ Yii::import('application.helpers.update.updatedb_helper', true);
+ $result=db_upgrade_all($currentDbVersion);/* @todo : fix bad echoing here */
+ if ($result) {
+ //printf(gT("Database has been successfully upgraded to version %s"),$dbversionnumber)."\n";
+ echo "Database has been successfully upgraded to version $newDbVersion \n";
+ } else {
+ //echo gT("Please fix this error in your database and try again")."\n";
+ echo "Please fix this error in your database and try again\n";
+ }
+ } else {
+ echo "no need update ".$newDbVersion ." ". $currentDbVersion ."\n";
+ }
+ }
+
+ /**
+ * Fonction to set all needed (and unneeded) config
+ * @return void
+ */
+ private function _setConfigs(){
+ /* default config */
+ $aDefaultConfigs = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config-defaults.php');
+ foreach($aDefaultConfigs as $sConfig=>$defaultConfig){
+ Yii::app()->setConfig($sConfig,$defaultConfig);
+ }
+ /* Fix for badly set rootdir */
+ $sRootDir=realpath(Yii::app()->basePath. DIRECTORY_SEPARATOR . "..") ;
+ Yii::app()->setConfig('rootdir',$sRootDir);
+ Yii::app()->setConfig('publicdir',$sRootDir);
+ Yii::app()->setConfig('homedir',$sRootDir);
+ Yii::app()->setConfig('tempdir',$sRootDir.DIRECTORY_SEPARATOR."tmp");
+ Yii::app()->setConfig('imagedir',$sRootDir.DIRECTORY_SEPARATOR."images");
+ Yii::app()->setConfig('uploaddir',$sRootDir.DIRECTORY_SEPARATOR."upload");
+ Yii::app()->setConfig('standardtemplaterootdir',$sRootDir.DIRECTORY_SEPARATOR."templates");
+ Yii::app()->setConfig('usertemplaterootdir',$sRootDir.DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."templates");
+ Yii::app()->setConfig('styledir',$sRootDir.DIRECTORY_SEPARATOR."styledir");
+ /* version */
+ $aVersionConfigs = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'version.php');
+ foreach($aVersionConfigs as $sConfig=>$versionConfig){
+ Yii::app()->setConfig($sConfig,$versionConfig);
+ }
+ /* LS 3 version */
+ Yii::app()->setConfig('runtimedir',$sRootDir.DIRECTORY_SEPARATOR."tmp".DIRECTORY_SEPARATOR."runtime");
+ if(file_exists(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'))
+ {
+ $config = require(Yii::app()->basePath. DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php');
+ if(is_array($config['config']) && !empty($config['config']))
+ {
+ foreach($config['config'] as $key=>$value)
+ Yii::app()->setConfig($key,$value);
+ }
+ }
+ $oSettings=SettingGlobal::model()->findAll();
+ if (count($oSettings) > 0)
+ {
+ foreach ($oSettings as $oSetting)
+ {
+ Yii::app()->setConfig($oSetting->getAttribute('stg_name'), $oSetting->getAttribute('stg_value'));
+ }
+ }
+ }
+
+}
+?>