1
+ <?php
2
+ /*=========================================================================
3
+ MIDAS Server
4
+ Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5
+ 69328 Lyon, FRANCE.
6
+
7
+ See Copyright.txt for details.
8
+ This software is distributed WITHOUT ANY WARRANTY; without even
9
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
+ PURPOSE. See the above copyright notices for more information.
11
+ =========================================================================*/
12
+
13
+ /** Demo management Componenet */
14
+ class DemoComponent extends AppComponent
15
+ {
16
+ /** reset database (only works with mysql)*/
17
+ public function reset ()
18
+ {
19
+ if (Zend_Registry::get ('configGlobal ' )->demomode != 1 )
20
+ {
21
+ throw new Zend_Exception ("Please enable demo mode " );
22
+ }
23
+
24
+ $ db = Zend_Registry::get ('dbAdapter ' );
25
+ $ dbname = Zend_Registry::get ('configDatabase ' )->database ->params ->dbname ;
26
+
27
+ $ stmt = $ db ->query ("SELECT * FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = ' $ dbname' " );
28
+ while ($ row = $ stmt ->fetch ())
29
+ {
30
+ $ db ->query ("DELETE FROM ` " .$ row ['TABLE_NAME ' ]."` " );
31
+ }
32
+
33
+ $ path = BASE_PATH .'/data/assetstore ' ;
34
+ $ dir = opendir ($ path );
35
+ while ($ entry = readdir ($ dir ))
36
+ {
37
+ if (is_dir ($ path .'/ ' .$ entry ) && !in_array ($ entry , array ('. ' ,'.. ' )))
38
+ {
39
+ $ this ->rrmdir ($ path .'/ ' .$ entry );
40
+ }
41
+ }
42
+
43
+ $ path = BASE_PATH .'/data/thumbnail ' ;
44
+ $ dir = opendir ($ path );
45
+ while ($ entry = readdir ($ dir ))
46
+ {
47
+ if (is_dir ($ path .'/ ' .$ entry ) && !in_array ($ entry , array ('. ' ,'.. ' )))
48
+ {
49
+ $ this ->rrmdir ($ path .'/ ' .$ entry );
50
+ }
51
+ }
52
+
53
+ if (file_exists (BASE_PATH .'/core/configs/ldap.local.ini ' ))
54
+ {
55
+ unlink (BASE_PATH .'/core/configs/ldap.local.ini ' );
56
+ }
57
+
58
+ $ modelLoad = new MIDAS_ModelLoader ();
59
+ $ userModel = $ modelLoad ->loadModel ('User ' );
60
+ $ communityModel = $ modelLoad ->loadModel ('Community ' );
61
+ $ assetstoreModel = $ modelLoad ->loadModel ('Assetstore ' );
62
+ $ admin = $ userModel ->createUser ('admin@kitware.com ' , 'admin ' , 'Demo ' , 'Administrator ' , 1 );
63
+ $ user = $ userModel ->createUser ('user@kitware.com ' , 'user ' , 'Demo ' , 'User ' , 0 );
64
+
65
+ $ communityDao = $ communityModel ->createCommunity ('Demo ' , "This is a Demo Community " , MIDAS_COMMUNITY_PUBLIC , $ admin , MIDAS_COMMUNITY_CAN_JOIN );
66
+
67
+ $ assetstoreDao = new AssetstoreDao ();
68
+ $ assetstoreDao ->setName ('Default ' );
69
+ $ assetstoreDao ->setPath (BASE_PATH .'/data/assetstore ' );
70
+ $ assetstoreDao ->setType (MIDAS_ASSETSTORE_LOCAL );
71
+ $ assetstoreModel ->save ($ assetstoreDao );
72
+
73
+ $ applicationConfig = parse_ini_file (BASE_PATH .'/core/configs/application.ini ' , true );
74
+ $ applicationConfig ['global ' ]['defaultassetstore.id ' ] = $ assetstoreDao ->getKey ();
75
+ $ applicationConfig ['global ' ]['demomode ' ] = true ;
76
+
77
+ if (file_exists (BASE_PATH .'/core/configs/visualize.demo.local.ini ' ))
78
+ {
79
+ copy (BASE_PATH .'/core/configs/visualize.demo.local.ini ' , BASE_PATH .'/core/configs/visualize.local.ini ' );
80
+ $ applicationConfig ['module ' ]['visualize ' ] = true ;
81
+ }
82
+
83
+ require_once BASE_PATH .'/core/controllers/components/UtilityComponent.php ' ;
84
+ $ utilityComponent = new UtilityComponent ();
85
+ $ utilityComponent ->createInitFile (BASE_PATH .'/core/configs/application.local.ini ' , $ applicationConfig );
86
+
87
+ $ configGlobal = new Zend_Config_Ini (APPLICATION_CONFIG , 'global ' , true );
88
+ Zend_Registry::set ('configGlobal ' , $ configGlobal );
89
+
90
+ require_once BASE_PATH .'/core/controllers/components/UploadComponent.php ' ;
91
+ $ uploadCompoenent = new UploadComponent ();
92
+ $ item = $ uploadCompoenent ->createUploadedItem ($ admin , 'midasLogo.gif ' , BASE_PATH .'/core/public/images/midasLogo.gif ' , $ communityDao ->getPublicFolder ());
93
+ }
94
+
95
+ /** recursively delete a folder*/
96
+ private function rrmdir ($ dir )
97
+ {
98
+ if (!file_exists ($ dir ))
99
+ {
100
+ return ;
101
+ }
102
+ if (is_dir ($ dir ))
103
+ {
104
+ $ objects = scandir ($ dir );
105
+ }
106
+
107
+ foreach ($ objects as $ object )
108
+ {
109
+ if ($ object != ". " && $ object != ".. " )
110
+ {
111
+ if (filetype ($ dir ."/ " .$ object ) == "dir " )
112
+ {
113
+ $ this ->rrmdir ($ dir ."/ " .$ object );
114
+ }
115
+ else
116
+ {
117
+ unlink ($ dir ."/ " .$ object );
118
+ }
119
+ }
120
+ }
121
+ reset ($ objects );
122
+ rmdir ($ dir );
123
+ }
124
+ } // end class
0 commit comments