I'm not sure anymore, I have about 20 UDTs that access another database, 3 or 4 of them were playing up after I moved the site to a new server. adding "adodb_connect();" at the end fixed the problem for all of them. However, some of my UDTs did not require this, but I ended up adding that line to all of them. The only other time I observed this problem is described here
http://forum.cmsmadesimple.org/viewtopi ... 48#p307348
but tristan was correct, my subsequent edit only triggered a cache refresh as I couldnt reproduce the problem when I rolled back the code.
here's a UDT that I believe stopped working at the time:
Code: Select all
//create link using (duplicated) SEO_URL logic
//script completely ignores SEO_URL backend settings
//ms 5.11.13
//requires products ID as params['id']
//optional:
//text, assign
//warning emails go to:
$webmaster = 'webdude@xxxxx';
// ------------------ dont edit below unless you know what you're doing --------------
//get database credentials
require "ms_config/db.php";
//connect - using ADOdb lite syntax
$db = NewADOConnection('mysql');
$db->Connect($db_host,$db_user,$db_pw,$db_db);
//products_id
$product = array((int)$params['id']);
//only active products, dont bother about language settings
$query = "SELECT products_name as pName, products_seo_url as psu FROM products_description pd JOIN products p ON pd.products_id = p.products_id WHERE pd.products_id = ? AND p.products_status = '1'";
$result = $db->GetArray($query,$product);
//send email on error
$error = false;
if (!$result ) {
$error=true;
$msg = 'Check product ID '.$product[0]. ' found on page (alias): '. $smarty->get_template_vars('page_alias');
mail($webmaster,'Error by osc_product_link UDT',$msg);
} else {
$row = $result;
//no error
//no URL? use name instead
if($row[0]['psu'] != '') {
$pName = $row[0]['psu'];
} else {
$pName = $row[0]['pName'];
}
//strip most special characters (not the underscore)
$pattern = "/([^a-zA-Z0-9_[:space:]])+/";
$anchor = preg_replace($pattern, '', trim(strtolower($pName)));
//replace with - dashes
$pattern = "/([[:space:]]|[[:blank:]])+/";
$anchor = preg_replace($pattern, '-', $anchor);
//strip short words ($limit), unless separated with underscores
$limit = 3;
$foo = @explode('-', $anchor);
foreach($foo as $index => $value){
switch (true){
case ( strlen($value) <= $limit ):
continue;
default:
$container[] = $value;
break;
}
}
$container = ( sizeof($container) > 1 ? implode('-', $container) : $anchor );
$container = str_replace('_','-',$container);
//get root url
$config = cmsms()->GetConfig();
$seo_url = $config['root_url'] . "/catalog/".$container ."-p-".$product[0] .".html";
if($params['text'] != '') {
$seo_url = '<a href="'.$seo_url.'">'.$params['text'].'</a>';
}
}
//assign results or print to screen
if(isset($params['assign']) && $params['assign'] != '' && !$error) {
$smarty->assign($params['assign'], $seo_url);
} else if(isset($params['assign']) && $params['assign'] != '' && $error && $params['text'] != '') {
$smarty->assign($params['assign'], $params['text']);
} else if(isset($params['assign']) && $params['assign'] != '' && $error) {
$smarty->assign($params['assign'], '#');
} else if(!$error) {
echo $seo_url;
} else if($error && $params['text'] != '') {
echo $params['text'];
} else if($error) {
echo '#';
}
adodb_connect();
the UDT requires a product ID and ideally some text, it connects to another DB and finds associated SEO URL and returns a link to that product, but more importantly, it sends an email when a product goes missing (disabled, deleted), in which case the UDT also returns plain text instead of a link. this way, the user is less likely to see that something is not quite right. BTW, i'd love to see a similar feature for links to disabled CMSMS pages (instead of a link to homepage).