ILIAS  Release_4_0_x_branch Revision 61816
 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  //define constants
54  define("ILIAS_WEB_DIR",$ini->readVariable("clients","path"));
55  define("ILIAS_ABSOLUTE_PATH",$ini->readVariable('server','absolute_path'));
56  define("ILIAS_CLIENT_ID",$ini->readVariable('clients','default'));
57  define("ILIAS_CLIENT_INI",$ini->readVariable('clients','inifile'));
58 
59  //build datapath for this ilias installation
61 
62  //client ini
64 
65  //get db connection data from client_ini
67  $cini->read();
68  define("ILIAS_DB_NAME",$cini->readVariable("db","name"));
69  define("ILIAS_DB_HOST",$cini->readVariable("db","host"));
70  define("ILIAS_DB_USER",$cini->readVariable("db","user"));
71  define("ILIAS_DB_PASS",$cini->readVariable("db","pass"));
72  define("ILIAS_DB_TYPE",$cini->readVariable("db","type"));
73 
74  //init db-connection
75 
76  $dbh = mysql_connect(ILIAS_DB_HOST, ILIAS_DB_USER, ILIAS_DB_PASS) or die("Unable to connect to MySQL");
77  $sel_db = mysql_select_db(ILIAS_DB_NAME,$dbh);
78 
79  //start directory processing - one level only
80 
81  $dirs=array();
82  $d = dir($search_path);
83  while (false !== ($entry = $d->read())) {
84  if($entry != '.' && $entry != '..' && is_dir($search_path."/".$entry)) {
85  array_push($dirs, $entry);
86  }
87  }
88  $d->close();
89 
90  //iterate over array
91 
92  for ($i=0;$i<count($dirs);$i++) {
93  //check for imsmanifest
94  $toparse=$search_path."/".$dirs[$i]."/imsmanifest.xml";
95  if (is_file($toparse)) {
96  //check for DB entry
97  //get id
98  $id = $webdir=str_replace("lm_","",$dirs[$i]);
99  $result = mysql_query("SELECT * FROM cp_package WHERE(obj_id=$id)");
100  $row = mysql_fetch_array($result,MYSQL_ASSOC);
101  if (count($row)>0 && strlen($row['jsdata'])>10) {
102  //create new parser
103  $builder=new SeqTreeBuilder();
104  $ret=$builder->buildNodeSeqTree($toparse);
105  $global=$ret['global'];
106  $adltree=mysql_escape_string(json_encode($ret['tree']));
107  $result_update = mysql_query("UPDATE cp_package SET activitytree='$adltree',global_to_system='$global' WHERE(obj_id=$id)") or die(mysql_error());
108  echo "Updated activitytree for: ".$dirs[$i]." Global:".$global." \n";
109  }
110  }
111  }
112 
113  mysql_close($dbh);
114 
115 ?>