ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
updateADLTree.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 /*
25  Script to update JSON Data for the activitytree - reads all manifest files in lm_data and updates
26  the filed activitytree in cp_package
27 
28  @author Hendrik Holtmann <holtmann@mac.com>
29 
30  This software is provided "AS IS," without a warranty of any kind. ALL
31  EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
32  ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
33  OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ADL Co-Lab Hub AND ITS LICENSORS
34  SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
35  USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO
36  EVENT WILL ADL Co-Lab Hub OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE,
37  PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
38  INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
39  THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE
40  SOFTWARE, EVEN IF ADL Co-Lab Hub HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
41  DAMAGES.
42 */
43 
44  require_once("adlparser/SeqTreeBuilder.php");
45  require_once("../../../classes/class.ilIniFile.php");
46 
47  //find all folders containing data
48  //initIliasIniFile()
49 
50  $ini=new ilIniFile("../../../ilias.ini.php");
51  $ini->read();
52 
53 
54 
55  //define constants
56  define("ILIAS_WEB_DIR",$ini->readVariable("clients","path"));
57  define("ILIAS_ABSOLUTE_PATH",$ini->readVariable('server','absolute_path'));
58  define("ILIAS_CLIENT_ID",$ini->readVariable('clients','default'));
59  define("ILIAS_CLIENT_INI",$ini->readVariable('clients','inifile'));
60 
61  //build datapath for this ilias installation
63 
64  //client ini
66 
67  //get db connection data from client_ini
69  $cini->read();
70  define("ILIAS_DB_NAME",$cini->readVariable("db","name"));
71  define("ILIAS_DB_HOST",$cini->readVariable("db","host"));
72  define("ILIAS_DB_USER",$cini->readVariable("db","user"));
73  define("ILIAS_DB_PASS",$cini->readVariable("db","pass"));
74  define("ILIAS_DB_TYPE",$cini->readVariable("db","type"));
75 
76  //init db-connection
77 
78  $dbh = mysql_connect(ILIAS_DB_HOST, ILIAS_DB_USER, ILIAS_DB_PASS) or die("Unable to connect to MySQL");
79  $sel_db = mysql_select_db(ILIAS_DB_NAME,$dbh);
80 
81  //start directory processing - one level only
82 
83  $dirs=array();
84  $d = dir($search_path);
85  while (false !== ($entry = $d->read())) {
86  if($entry != '.' && $entry != '..' && is_dir($search_path."/".$entry)) {
87  array_push($dirs, $entry);
88  }
89  }
90  $d->close();
91 
92  //iterate over array
93 
94  for ($i=0;$i<count($dirs);$i++) {
95  //check for imsmanifest
96  $toparse=$search_path."/".$dirs[$i]."/imsmanifest.xml";
97  if (is_file($toparse)) {
98  //check for DB entry
99  //get id
100  $id = $webdir=str_replace("lm_","",$dirs[$i]);
101  $result = mysql_query("SELECT * FROM cp_package WHERE(obj_id=$id)");
102  $row = mysql_fetch_array($result,MYSQL_ASSOC);
103  if (count($row)>0 && strlen($row['jsdata'])>10) {
104  //create new parser
105  $builder=new SeqTreeBuilder();
106  $ret=$builder->buildNodeSeqTree($toparse);
107  $global=$ret['global'];
108  $adltree=mysql_escape_string(json_encode($ret['tree']));
109  $result_update = mysql_query("UPDATE cp_package SET activitytree='$adltree',global_to_system='$global' WHERE(obj_id=$id)") or die(mysql_error());
110  echo "Updated activitytree for: ".$dirs[$i]." Global:".$global." \n";
111  }
112  }
113  }
114 
115  mysql_close($dbh);
116 
117 ?>