PowerShell: Add Reference to COM Interface ID directly - powershell

Is there by any chance a posibility to create a reference to an Interface ID Directly.
I tried something in a syntax form like but didnt work ...
$CO = new-object -ComObject "System.__ComObject#{fafa4e17-1ee2-4905-a10e-fe7c18bf5554}"
This Interface id is from Virtualbox.VirtualBox itself
I know that I can reference it with VirtualBox.VirtualBox naturally.
Can you refernce interface ids directly .... ??
As long the Interface is Public I Think you can but i cant find any example . ??
Thanks:)

I found the solution to my own problem by accessing it through:
[System.Runtime.InteropServices.Marshal]::GetTypeFromCLSID('fafa4e17-1ee2-4905-a10e-fe7c18bf5554')
OR:
$Type = [Type]::GetTypeFromCLSID('fafa4e17-1ee2-4905-a10e-fe7c18bf5554')
$Vbox = [System.Activator]::CreateInstance($Type)
$Vbox.APIVersion
This answered my question; case closed :)

Related

Using "processDatamap_afterDatabaseOperations" with "tx_news_domain_model_news" and status "new" ends up without empty category

I'm using the "processDatamap_afterDatabaseOperations" hook within my extension to transfer content from a newly created News (tx_news_domain_model_news) to an API.
TYPO3 Version is 6.2.11 and if I var_dump or trying to access the category using $record->getCategories() it's empty. Same with related files, falmedia works. Here is my code:
public function processDatamap_afterDatabaseOperations($status, $table, $id, array $fieldArray, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {
if ($table == 'tx_news_domain_model_news' && $status == 'new') {
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
$news = $objectManager->get('GeorgRinger\News\Domain\Repository\NewsRepository');
$record = $news->findByUid($pObj->substNEWwithIDs[$id]);
Hope anybody knows what I'm doing wrong here. I've been trying this like forever and don't get it.
Thanks in advance for your help.
That's likely because "afterDatabaseOperations" is called for each record insertion/update in each table, and that the relation between the record and the categories has not been established yet.
Only after all insertions/updates have been done, the method processRemapStack is called by the DataHandler, that sets/fixes all the relations between the various records (e.g. wherever there was a "NEW.." relation in the datamap, the correct uids are set).
The only hook you can use, where alle records have the correct relations is the processDatamap_afterAllOperations hook, that you can find at the very end of the process_datamap in the DataHandler class.
That one only takes a single argument though (the DataHandler instance), so you probably have to try and get the inserted news records using the "datamap" property of the DataHandler reference.

Convert lead into a contact using a logic hook

I looked in the dev guide and online but can't seem to find any code examples. I'm just trying to convert a lead into a contact.
For example I have a lead with ID: 7, what I'm trying to do is possibly modify a bean property to convert that lead into a contact (not sure if this approach is correct). Something like
$bean->convert("Contact");
$bean->save();
Thank you for your advice
In sugar/suite, conversion is a process which is copying a bean from one module to another module e.g. lead into contact.
I have been using this function to make it happen.
function outright_copy_bean($old_bean){
$new_bean = new $old_bean->object_name;
foreach($new_bean->field_defs as $key => $value){
if(in_array($key, array("id", "date_entered"))){
continue;
}
if($value["type"] == "link"){
continue;
}
$new_bean->$key = $old_bean->$key;
}
$new_id = $new_bean->save();
return $new_id
}

What is the best way to get the action name with Zend Framework

I'm pretty new to Zend digging the docs but i can't find a good way to get the parameter i passed to my action...
Here is my uri :
/entreprise/name/foo
I would like to extract the name, foo. I'm actually able to get the action name with
$this->getRequest()->getActionName();
or the URI with
$this->getRequest()->getRequestUri();
With these two data i can parse the second string and get the name of my entreprise, but i quite surprised there is no best way to do this...
Is there a best to way to it ?
Get the action name with:
$this->getRequest()->getActionName();
And additional data passed to this action by GET with:
$name = $this->_getParam('name', NULL);
This will get the GET-Value name if passed by URI, if not $name is set to null.
Edit:
As mentioned in the comments the way to pass vars is a bit different. Change it to
/entreprise/name/var/foo
And you'll be able to access foo this way:
$var = $this->_getParam('var', NULL);
In the following URI : /entreprise/name/foo if entreprise is your controller and name is your action, then the additional parameter will be used to call your action so you can get it by doing the following:
public function nameAction( $name = null )
{
// $name == "foo"
}

zend loading models using eval in helpers

i want to load models from helpers... im using eval to insert the modelname etc.
public function getMod($mName) {
// this works but need a dynamic one
$model = $this->users = new Application_Model_Users();
// so i did this:
$model = $this->_listsMod = eval ("new Application_Model_$mName();");
return $model;
and you can call it by: $this->_helper->getmod->getMod('Users')->myuserFunc();
but it doesnt work, its says Fatal error: Call to a member function myuserFunc() on a non-object
Updated answer:
Have you tried:
$modelName = 'Application_Model_'.$mName;
$model = $this->_lists = new $modelName ;
?
You should have a look at the Factory Pattern (which is effectively what you're doing here) eg here and here.
As you probably know, its best to avoid using eval if possible. Also, it seems a bit odd needing to load Models like this - can you tell us why you need to load them like this?
Note: I've updated this answer following comments below, to make it quicker for future readers of the question / answer.

Easy way to get "params" from Joomla menu table

I don't know too much about Joomla, but I'm trying to work with a Menu on a Joomla site. In the Database I can see a column called params in the menu table, and it has some data I need. The params column has this data:
categories=446
feedLink=1
fusion_item_subtext=
fusion_columns=1
fusion_customimage=
splitmenu_item_subtext=
page_title=
show_page_title=1
pageclass_sfx=
menu_image=-1
secure=0
I know I can do a mysql query, get that column and parse the value using string manipulation/regex, but that doesn't sound like the right way.
I have seen some code in Joomla that looks like:
$cid = $params->get('secure');
Does Joomla have a special way to query and return objects so that these params are accessible with this type of syntax?
Right way is to use JMenu::getParams method
$app =& JFactory::getApplication();
$menu =& $app->getMenu();
$params = $menu->getParams($menuItemId);
$params->get('paramName');
Yes, Joomla does have special way of getting the parameters in an easily accessible object based on JObject.
you can get the entire site menu with this
$menu = JFactory::getApplication()->getMenu();
$item = $menu->getActive(); // will get active menu item. can use getItem() instead to get specific item
$item->get('parmName');
This is not exact code, more like pseudocode. This will get you on the right track...
Helpfull Stuff:
Joomla Framework API
JMenu Documentation
first you get a JApplication instance like this
$app = & JFactory::getApplication();
or for joomla 1.5 use:
global $mainframe //to get JApplication object
get JMenu instance like this:
$menu = $app->getMenu();
you can get active menu params or any other menu params like this
$active = $menu->getActive(); //get active menu
$menuInstance = $menu->getActive($Itemid); // to get Itemid use JRequest::getInt('Itemid', 0);
here you have an StdClass object with params field inside, now u use JParameter class like this
$menuParams = new JParameter($menuInstance->params);
here you have it, to get any parameter you want:
$someParam = $menuParams->get('some_param', 'default');