Skip to content

Instantly share code, notes, and snippets.

@kochen
Last active November 2, 2015 19:34
Show Gist options
  • Save kochen/425247bc02f395c6f3ff to your computer and use it in GitHub Desktop.
Save kochen/425247bc02f395c6f3ff to your computer and use it in GitHub Desktop.
DOCman 2.0 Stable - add new document
<?
$catid = 2; // the number of the specific category to assign the document to.
$fileinfo = array( /* an array of file info, including BASENAME and FILENAME */ );
$datetime = date("Y-m-d H:i:s"); // current datetime
$user = KObjectMAnager::getInstance()->getObject('user'); // the Joomla user object
$controller = KObjectMAnager::getInstance()->getObject('com://admin/docman.controller.document');
$controller->add(array(
docman_category_id => $catid,
storage_path => $fileinfo['filename'],
title => $fileinfo['basename'],
created_on => $datetime,
modified_on => $datetime,
modified_bycr => $user->id,
created_by => $user->id,
));
@johanjanssens
Copy link

If something goes wrong with this call an exception will be thrown at all times. Depending on what went wrong different exceptions are thrown and can be catched. We do not have a list of exceptions per method.

A. During development the adviced approach is to install our Joomla Vagrant Box which offers support for xdebug and makes full use of the build in framework debugger. This gives you complete stack tracing and exception output if something goes wrong.

To do so :

  1. Install the Joomla Vagrant box : http://developer.joomlatools.com/tools/vagrant/introduction.html and http://www.slideshare.net/joomlatools/joomla-in-a-box
  2. Turn on debug in Joomla
  3. Turn on xdebug on the command line (vagrant ssh > xdebug enable)

The last step is not required by useful for debugging fatal errors intead of exceptions. You get a complete stacktrace this way, which php doesn't provide out of the box.

B. During production it makes sense to catch exceptions that could occur. For example you can wrap the call in

try 
{
    //Code goes here
} catch (Exception $exception) {
    //Exception handling goes here
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment