Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature: CLI command to wipe a LimeSurvey installation
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/* | ||
* LimeSurvey (tm) | ||
* Copyright (C) 2011 The LimeSurvey Project Team / Carsten Schmitz | ||
* All rights reserved. | ||
* License: GNU/GPL License v2 or later, see LICENSE.php | ||
* LimeSurvey is free software. This version may have been modified pursuant | ||
* to the GNU General Public License, and as distributed it includes or | ||
* is derivative of works licensed under the GNU General Public License or | ||
* other free or open source software licenses. | ||
* See COPYRIGHT.php for copyright notices and details. | ||
*/ | ||
class WipeCommand extends CConsoleCommand | ||
{ | ||
|
||
public function run($sArgument) | ||
{ | ||
if (!isset($sArgument) || !isset($sArgument[0]) || $sArgument[0]!='yes') die('This CLI command wipes a LimeSurvey installation clean (including all user except for the user ID 1). For security reasons this command can only started if you add the parameter \'yes\' to the command line.'); | ||
Yii::import('application.helpers.common_helper', true); | ||
Yii::import('application.helpers.database_helper', true); | ||
|
||
$actquery="truncate table {{assessments}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{answers}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{conditions}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{defaultvalues}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{labels}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{labelsets}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{groups}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{questions}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{surveys}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{surveys_languagesettings}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{survey_permissions}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{quota}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{quota_members}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{quota_languagesettings}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{templates_rights}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{question_attributes}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{user_groups}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{user_in_groups}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{templates}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{participants}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{participant_attribute_names}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{participant_attribute_names_lang}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{participant_attribute_values}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{participant_shares}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="truncate table {{failed_login_attempts}}"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="delete from {{users}} where uid<>1"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
$actquery="update {{users}} set lang='en'"; | ||
Yii::app()->db->createCommand($actquery)->execute(); | ||
debugbreak(); | ||
|
||
$surveyidresult = dbGetTablesLike("tokens%"); | ||
foreach ( $surveyidresult as $sv ) | ||
{ | ||
Yii::app()->db->createCommand("drop table ".reset($sv))->execute(); | ||
} | ||
|
||
$surveyidresult = dbGetTablesLike("old\_%"); | ||
foreach ( $surveyidresult as $sv ) | ||
{ | ||
Yii::app()->db->createCommand("drop table ".reset($sv))->execute(); | ||
} | ||
|
||
$surveyidresult = dbGetTablesLike("survey\_%"); | ||
foreach ( $surveyidresult as $sv ) | ||
{ | ||
$sv = reset($sv); | ||
if (strpos($sv, 'survey_links')===false && strpos($sv, 'survey_permissions')===false) | ||
Yii::app()->db->createCommand("drop table ".$sv)->execute(); | ||
} | ||
} | ||
|
||
} |