/**
  * Syncs the files in the db with the files in the filesystem
  *
  * @param string $strPrevID
  * @param string $strPath
  * @param bool $bitRecursive
  * @param \class_module_mediamanager_repo|null $objRepo
  *
  * @return array [insert, delete]
  */
 public static function syncRecursive($strPrevID, $strPath, $bitRecursive = true, class_module_mediamanager_repo $objRepo = null)
 {
     $arrReturn = array();
     $arrReturn["insert"] = 0;
     $arrReturn["delete"] = 0;
     if ($objRepo == null) {
         $objRepo = class_objectfactory::getInstance()->getObject($strPrevID);
         while ($objRepo != null && !$objRepo instanceof class_module_mediamanager_repo) {
             $objRepo = class_objectfactory::getInstance()->getObject($objRepo->getPrevId());
         }
     }
     //Load the files in the DB
     $arrObjDB = class_module_mediamanager_file::loadFilesDB($strPrevID);
     //Load files and folder from filesystem
     $objFilesystem = new class_filesystem();
     //if the repo defines a view-filter, take that one into account
     $arrViewFilter = array();
     if ($objRepo->getStrViewFilter() != "") {
         $arrViewFilter = explode(",", $objRepo->getStrViewFilter());
     }
     $arrFilesystem = $objFilesystem->getCompleteList($strPath, $arrViewFilter, array(), array(".", "..", ".svn"));
     //So, lets sync those two arrays
     //At first the files
     foreach ($arrFilesystem["files"] as $intKeyFS => $arrOneFileFilesystem) {
         //search the db-array for this file
         foreach ($arrObjDB as $intKeyDB => $objOneFileDB) {
             //File or folder
             if ($objOneFileDB->getintType() == self::$INT_TYPE_FILE) {
                 //compare
                 if ($objOneFileDB->getStrFilename() == str_replace(_realpath_, "", $arrOneFileFilesystem["filepath"])) {
                     //And unset from both arrays
                     unset($arrFilesystem["files"][$intKeyFS]);
                     unset($arrObjDB[$intKeyDB]);
                 }
             }
         }
     }
     //And loop the folders
     foreach ($arrFilesystem["folders"] as $intKeyFolder => $strFolder) {
         //search the array for folders
         foreach ($arrObjDB as $intKeyDB => $objOneFolderDB) {
             //file or folder?
             if ($objOneFolderDB->getIntType() == self::$INT_TYPE_FOLDER) {
                 //compare
                 if ($objOneFolderDB->getStrFilename() == $strPath . "/" . $strFolder) {
                     //Unset from both
                     unset($arrFilesystem["folders"][$intKeyFolder]);
                     unset($arrObjDB[$intKeyDB]);
                 }
             }
         }
     }
     //the remaining records from the database have to be deleted!
     if (count($arrObjDB) > 0) {
         foreach ($arrObjDB as $objOneFileDB) {
             $objOneFileDB->deleteObjectFromDatabase();
             $arrReturn["delete"]++;
         }
     }
     //the remaining records from the filesystem have to be added
     foreach ($arrFilesystem["files"] as $arrOneFileFilesystem) {
         $strFileName = $arrOneFileFilesystem["filename"];
         $strFileFilename = str_replace(_realpath_, "", $arrOneFileFilesystem["filepath"]);
         $objFile = new class_module_mediamanager_file();
         $objFile->setStrFilename($strFileFilename);
         $objFile->setStrName($strFileName);
         $objFile->setIntType(self::$INT_TYPE_FILE);
         $objFile->updateObjectToDb($strPrevID);
         $arrReturn["insert"]++;
     }
     foreach ($arrFilesystem["folders"] as $strFolder) {
         $strFileName = $strFolder;
         $strFileFilename = $strPath . "/" . $strFolder;
         $objFile = new class_module_mediamanager_file();
         $objFile->setStrFilename($strFileFilename);
         $objFile->setStrName($strFileName);
         $objFile->setIntType(self::$INT_TYPE_FOLDER);
         $objFile->updateObjectToDb($strPrevID);
         $arrReturn["insert"]++;
     }
     //Load subfolders
     class_carrier::getInstance()->getObjDB()->flushQueryCache();
     if ($bitRecursive) {
         $objFolders = class_module_mediamanager_file::loadFilesDB($strPrevID, self::$INT_TYPE_FOLDER);
         foreach ($objFolders as $objOneFolderDB) {
             $arrTemp = class_module_mediamanager_file::syncRecursive($objOneFolderDB->getSystemid(), $objOneFolderDB->getStrFilename(), $bitRecursive, $objRepo);
             $arrReturn["insert"] += $arrTemp["insert"];
             $arrReturn["delete"] += $arrTemp["delete"];
         }
     }
     return $arrReturn;
 }
 /**
  * Copies the metadata.xml content into the files properties.
  * @permissions edit
  * @xml
  * @return string
  */
 protected function actionUpdateDataFromMetadata()
 {
     $objPackage = new class_module_mediamanager_file($this->getSystemid());
     $objZip = new class_zip();
     $strMetadata = $objZip->getFileFromArchive($objPackage->getStrFilename(), "/metadata.xml");
     if ($strMetadata !== false) {
         $objMetadata = new class_module_packagemanager_metadata();
         $objMetadata->autoInit($objPackage->getStrFilename());
         $objPackage->setStrName($objMetadata->getStrTitle());
         $objPackage->setStrDescription($objMetadata->getStrDescription());
         //updateObjectToDb triggers the update of the isPackage and the category flags
         $objPackage->updateObjectToDb();
         return "<message><success /></message>";
     }
     return "<message><error /></message>";
 }