Alterations to UserAttributeKey class
Permalink
I made some alterations to my UserAttributeKey class because I couldn't get the job done with out a fatal error.
Goal:
To delete UserAttributes that where created when the package was installed. They where created with the following:
$pkg = parent::install();
Loader::model('user_attributes');
$user_att = UserAttributeKey::add('example_att','Attribute', 1, 1, 0, 1, '0', 'TEXT');
The problem:
When I try to use the UserAttributeKey::delete I get a fatal error:
Fatal error: Call to undefined method ExamplePackage::getKeyID() in (..path..)\concrete\models\user_attributes.php on line 84
the (..path..) was my modification
The code I used was:
$pkg = parent::uninstall();
Loader::model('user_attributes');
//Doesn't delete all notations
$user_att_use = UserAttributeKey::inUse('example_att');
$user_att = UserAttributeKey::delete();
My fix:
I created 2 new functions that take $ukID or $ukHandle as a parameter and I deleted the problem line.
function deleteByID($ukID) {
// this removes the record from the CAKeys table, and from the CTypeAttributes tables, but
// not from the actual CAValues table, nor from the lookup columns
$db = Loader::db();
$db->query("delete from UserAttributeKeys where ukID = ?", $ukID);
$db->query("delete from UserAttributeValues where ukID = ?", $ukID);
}
function deleteByHandle($ukHandle) {
// this removes the record from the CAKeys table, and from the CTypeAttributes tables, but
// not from the actual CAValues table, nor from the lookup columns
$db = Loader::db();
$db->query("delete from UserAttributeKeys where ukHandle = ?", $ukHandle);
$db->query("delete from UserAttributeValues where ukHandle = ?", $ukHandle);
}
Notice:
The mysterious thing of this error was that even if I got it, it still did delete the attribute.
Conclusion:
I might not have used the delete correctly, please tell me what did I do wrong. The solution I made might be handy because for example in my case I knew the ukHandle name of the created attribute.
Goal:
To delete UserAttributes that where created when the package was installed. They where created with the following:
$pkg = parent::install();
Loader::model('user_attributes');
$user_att = UserAttributeKey::add('example_att','Attribute', 1, 1, 0, 1, '0', 'TEXT');
The problem:
When I try to use the UserAttributeKey::delete I get a fatal error:
Fatal error: Call to undefined method ExamplePackage::getKeyID() in (..path..)\concrete\models\user_attributes.php on line 84
the (..path..) was my modification
The code I used was:
$pkg = parent::uninstall();
Loader::model('user_attributes');
//Doesn't delete all notations
$user_att_use = UserAttributeKey::inUse('example_att');
$user_att = UserAttributeKey::delete();
My fix:
I created 2 new functions that take $ukID or $ukHandle as a parameter and I deleted the problem line.
function deleteByID($ukID) {
// this removes the record from the CAKeys table, and from the CTypeAttributes tables, but
// not from the actual CAValues table, nor from the lookup columns
$db = Loader::db();
$db->query("delete from UserAttributeKeys where ukID = ?", $ukID);
$db->query("delete from UserAttributeValues where ukID = ?", $ukID);
}
function deleteByHandle($ukHandle) {
// this removes the record from the CAKeys table, and from the CTypeAttributes tables, but
// not from the actual CAValues table, nor from the lookup columns
$db = Loader::db();
$db->query("delete from UserAttributeKeys where ukHandle = ?", $ukHandle);
$db->query("delete from UserAttributeValues where ukHandle = ?", $ukHandle);
}
Notice:
The mysterious thing of this error was that even if I got it, it still did delete the attribute.
Conclusion:
I might not have used the delete correctly, please tell me what did I do wrong. The solution I made might be handy because for example in my case I knew the ukHandle name of the created attribute.
Thanks sebmel!
Am waiting for a respone from the C5 Gods to this topic too ;)