16 if ( !is_object($instance) ){
29 if ( !isset($this->_db_versions) ){
30 $this->_db_versions = array();
31 $sql =
"select module_name, module_version from dataface__modules";
32 $res = mysql_query($sql, df_db());
34 $res = mysql_query(
"create table dataface__modules (
35 module_name varchar(255) not null primary key,
36 module_version int(11)
38 if ( !$res )
throw new Exception(mysql_error(df_db()));
39 $res = mysql_query($sql, df_db());
41 if ( !$res )
throw new Exception(mysql_error(df_db()));
42 while ($row = mysql_fetch_assoc($res) ){
43 $this->_db_versions[$row[
'module_name']] = $row[
'module_version'];
45 @mysql_free_result($res);
48 $out = @$this->_db_versions[$modname];
49 if ( !
$out )
return 0;
66 $versionPath = dirname(
$path).DIRECTORY_SEPARATOR.
'version.txt';
67 if ( !file_exists($versionPath) )
return 0;
68 $str = trim(file_get_contents($versionPath));
69 if ( preg_match(
'/(\d+)$/', $str, $matches) ){
70 return intval($matches[1]);
83 $installpath = dirname(
$path).DIRECTORY_SEPARATOR.
'installer.php';
84 if ( file_exists($installpath) ){
86 $classname = $modname.
'_installer';
89 $methods = get_class_methods($classname);
90 $methods = preg_grep(
'/^update_([0-9]+)$/', $methods);
96 foreach ($methods as $method){
97 preg_match(
'/^update_([0-9]+)$/', $method, $matches);
98 $version = intval($matches[1]);
99 if ( $version > $dbversion and $version <= $fsversion ){
100 $updates[] = $version;
106 if ( $dbversion == 0 ){
107 $res = mysql_query(
"insert into dataface__modules (module_name,module_version)
108 values ('".addslashes($modname).
"',-1)", df_db());
109 if ( !$res )
throw new Exception(mysql_error(df_db()));
112 foreach ($updates as $update ){
113 $method =
'update_'.$update;
116 $res = mysql_query(
"update dataface__modules set `module_version`='".addslashes($update).
"'", df_db());
117 if ( !$res )
throw new Exception(mysql_error(df_db()), E_USER_ERROR);
120 $res = mysql_query(
"update dataface__modules set `module_version`='".addslashes($fsversion).
"'", df_db());
121 if ( !$res )
throw new Exception(mysql_error(df_db()), E_USER_ERROR);
153 $s = DIRECTORY_SEPARATOR;
154 if ( strtolower(realpath($file)) == strtolower(realpath(DATAFACE_SITE_PATH.$s.
'modules'.$s.basename(dirname($file)).$s.basename($file))) ){
155 return DATAFACE_SITE_URL.
'/modules/'.rawurlencode(basename(dirname($file)));
156 }
else if (realpath($file) == realpath(DATAFACE_PATH.$s.
'modules'.$s.basename(dirname($file)).$s.basename($file)) ){
157 return DATAFACE_URL.
'/modules/'.rawurlencode(basename(dirname($file)));
159 throw new Exception(
"Could not find URL for file $file in module tool");
176 if ( !isset(
$app->_conf[
'_modules']) or count(
$app->_conf[
'_modules']) == 0 ){
180 foreach (
$app->_conf[
'_modules'] as $name=>
$path){
183 if ( method_exists($mod,
'block__'.$blockName) ){
185 $res = call_user_func(array(&$mod,
'block__'.$blockName), $params);
186 if ( !$res !==
false ){
201 if ( !isset(
$path) ){
202 if ( preg_match(
'/^modules_/', $name) ){
203 $s = DIRECTORY_SEPARATOR;
204 $path = preg_replace(
'/^modules_/',
'modules'.$s, $name).$s.substr($name, strpos($name,
'_')+1).
'.php';
210 if ( isset($this->_modules[$name]) )
return $this->_modules[$name];
211 if ( class_exists($name) ){
212 $this->_modules[$name] =
new $name;
213 return $this->_modules[$name];
216 if ( !isset(
$path) and (!@
$app->_conf[
'_modules'] or !is_array(
$app->_conf[
'_modules']) or !isset(
$app->_conf[
'_modules'][$name])) ){
219 'scripts.Dataface.ModuleTool.loadModule.ERROR_MODULE_DOES_NOT_EXIST',
220 "The module '$name' does not exist.",
225 if ( !isset(
$app->_conf[
'_modules'][$name]) and isset(
$path) ){
233 import(
$app->_conf[
'_modules'][$name]);
238 if ( !class_exists($name) ){
241 'scripts.Dataface.ModuleTool.loadModule.ERROR_CLASS_DOES_NOT_EXIST',
242 "Attempted to load the module '$name' from path '{$app->_conf['_modules'][$name]}' but after loading - no such class was found. Please check to make sure that the class is defined. Or you can disable this module by commenting out the line that says '{$name}={$app->_conf['_modules'][$name]}' in the conf.ini file.",
243 array(
'name'=>$name,
'path'=>
$app->_conf[
'_modules'][$name])
247 $this->_modules[$name] =
new $name;
248 return $this->_modules[$name];
256 if ( @
$app->_conf[
'_modules'] and is_array(
$app->_conf[
'_modules']) ){
257 foreach ( array_keys(
$app->_conf[
'_modules']) as $module){
271 foreach ($this->_modules as $name=>$mod ){
272 if ( method_exists($mod,
'requiresMigration') and ( $req = $mod->requiresMigration()) ){
293 foreach ($modules as $mod){
295 if ( isset($migrations[$mod]) and method_exists( $mod_obj,
'migrate' ) ){
296 $log[$mod] = $mod_obj->migrate();
313 foreach ($modules as $mod){
316 if ( !$this->isInstalled($mod) and method_exists($mod_obj,
'install') ){
317 $log[$mod] = $mod_obj->install();