Exemple #1
0
 /**
  * Delete object and values.
  * If object is a primary resource, this deletion is submitted to validation and an email is sent to validators.
  *
  * @param boolean $hardDelete : completely destroy object and associated resource if any. After this, this object will no longer exists at all. Default : false.
  * /!\ if object is a primary resource, no validation will be queried to validators, object will be directly destroyed from all locations. /!\
  * @return boolean true on success, false on failure
  * @access public
  */
 function delete($hardDelete = false)
 {
     global $cms_user;
     //get Object definition
     $objectDef = $this->getObjectDefinition();
     //get module codename
     $polyModuleCodename = $objectDef->getValue('module');
     //if object is not a primary resource
     if ($this->_objectResourceStatus != 1 || $hardDelete) {
         $forceSecondaryRessourcePublication = false;
         if ($this->_objectResourceStatus == 2 && !$hardDelete) {
             //if this object is a secondary resource, primary items which uses this object must be updated
             //get all primary resource associated
             $primaryItems = CMS_poly_object_catalog::getPrimaryItemsWhichUsesSecondaryItem($this->_ID, true, false);
             if ($primaryItems) {
                 foreach ($primaryItems as $primaryItem) {
                     $primaryItem->writeToPersistence();
                 }
             } else {
                 $forceSecondaryRessourcePublication = true;
             }
         }
         //if object is not a secondary resource, delete public datas, else preserve it : it will be deleted on primary resource validation
         if ($this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication || $hardDelete) {
             //delete datas from public locations
             CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_PUBLIC, RESOURCE_DATA_LOCATION_DEVNULL);
             if (!$hardDelete) {
                 //mark item as deleted
                 CMS_modulePolymodValidation::markDeletedItem($this->getID());
             } else {
                 //destroy poly_object reference
                 $sql = "delete from mod_object_polyobjects where id_moo = '" . $this->getID() . "'";
                 new CMS_query($sql);
             }
         }
         if ($this->_objectResourceStatus != 1 && $this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication) {
             $modulesCodes = new CMS_modulesCodes();
             //add a call to all modules for before validation specific treatment
             $modulesCodes->getModulesCodes(MODULE_TREATMENT_BEFORE_VALIDATION_TREATMENT, '', $this, array('result' => VALIDATION_OPTION_ACCEPT, 'lastvalidation' => true, 'module' => $polyModuleCodename, 'action' => 'delete'));
         }
         if (!$hardDelete) {
             //move resource datas from edited to deleted location
             CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_DELETED);
         } else {
             //delete datas from edited locations
             CMS_modulePolymodValidation::moveResourceData($polyModuleCodename, $this->getID(), RESOURCE_DATA_LOCATION_EDITED, RESOURCE_DATA_LOCATION_DEVNULL);
         }
         if ($this->_objectResourceStatus != 1 && $this->_objectResourceStatus != 2 || $this->_objectResourceStatus == 2 && $forceSecondaryRessourcePublication) {
             //add a call to all modules for after validation specific treatment
             $modulesCodes->getModulesCodes(MODULE_TREATMENT_AFTER_VALIDATION_TREATMENT, '', $this, array('result' => VALIDATION_OPTION_ACCEPT, 'lastvalidation' => true, 'module' => $polyModuleCodename, 'action' => 'delete'));
         }
         if ($this->_objectResourceStatus == 1 && $hardDelete) {
             //delete associated resource
             parent::destroy();
         }
         //Log action
         $log = new CMS_log();
         $language = $cms_user->getLanguage();
         $log->logMiscAction(CMS_log::LOG_ACTION_RESOURCE_DELETE, $cms_user, 'Item \'' . $this->getLabel() . '\' (' . $objectDef->getLabel($language) . ')', $polyModuleCodename);
         if ($hardDelete) {
             unset($this);
         }
         //Clear polymod cache
         //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $polyModuleCodename));
         CMS_cache::clearTypeCache('polymod');
         return true;
     } else {
         //change the article proposed location and send emails to all the validators
         if ($this->setProposedLocation(RESOURCE_LOCATION_DELETED, $cms_user)) {
             parent::writeToPersistence();
             if (APPLICATION_ENFORCES_WORKFLOW) {
                 if (!NO_APPLICATION_MAIL) {
                     //get editors
                     $editors = $this->getEditors();
                     $editorsIds = array();
                     foreach ($editors as $editor) {
                         $editorsIds[] = $editor->getUserId();
                     }
                     $validators = CMS_profile_usersCatalog::getValidators($polyModuleCodename);
                     foreach ($validators as $validator) {
                         //add script to send email for validator if needed
                         CMS_scriptsManager::addScript($polyModuleCodename, array('task' => 'emailNotification', 'object' => $this->getID(), 'validator' => $validator->getUserId(), 'type' => 'delete', 'editors' => $editorsIds));
                     }
                     //then launch scripts execution
                     CMS_scriptsManager::startScript();
                 }
             } else {
                 $validation = new CMS_resourceValidation($polyModuleCodename, RESOURCE_EDITION_LOCATION, $this);
                 $mod = CMS_modulesCatalog::getByCodename($polyModuleCodename);
                 $mod->processValidation($validation, VALIDATION_OPTION_ACCEPT);
             }
             //Log action
             $log = new CMS_log();
             $language = $cms_user->getLanguage();
             $log->logResourceAction(CMS_log::LOG_ACTION_RESOURCE_DELETE, $cms_user, $polyModuleCodename, $this->getStatus(), 'Item \'' . $this->getLabel() . '\' (' . $objectDef->getLabel($language) . ')', $this);
             //Clear polymod cache
             //CMS_cache::clearTypeCacheByMetas('polymod', array('module' => $polyModuleCodename));
             CMS_cache::clearTypeCache('polymod');
             return true;
         } else {
             return false;
         }
     }
 }
Exemple #2
0
 /**
  * Module script task
  * @param array $parameters the task parameters
  *		task : string task to execute
  *		object : string module codename for the task
  *		field : string module uid
  *		...	: optional field relative parameters
  * @return Boolean true/false
  * @access public
  */
 function scriptTask($parameters)
 {
     switch ($parameters['task']) {
         case 'emailNotification':
             @set_time_limit(300);
             $module = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
             //create a new script for all recipients
             $allUsers = $this->_getRecipients($parameters['object']);
             foreach ($allUsers as $userId) {
                 //add script to send email for user if needed
                 CMS_scriptsManager::addScript($module, array('task' => 'emailSend', 'user' => $userId, 'field' => $parameters['field'], 'object' => $parameters['object']));
             }
             //then set sending date to current date
             $sendingDate = new CMS_date();
             $sendingDate->setNow();
             $this->_subfieldValues[1]->setValue($sendingDate->getDBValue());
             $this->writeToPersistence();
             break;
         case 'emailSend':
             @set_time_limit(300);
             $params = $this->getParamsValues();
             if (!sensitiveIO::isPositiveInteger($parameters['user'])) {
                 return false;
             }
             //instanciate script related item
             $item = CMS_poly_object_catalog::getObjectByID($parameters['object'], false, true);
             if (!is_object($item) || $item->hasError()) {
                 return false;
             }
             //instanciate user
             $cms_user = new CMS_profile_user($parameters['user']);
             //check user
             if (!$cms_user || $cms_user->hasError() || !$cms_user->isActive() || $cms_user->isDeleted() || !sensitiveIO::isValidEmail($cms_user->getEmail())) {
                 return false;
             }
             $cms_language = $cms_user->getLanguage();
             //globalise cms_user and cms_language
             $GLOBALS['cms_language'] = $cms_user->getLanguage();
             $GLOBALS['cms_user'] = $cms_user;
             //check user clearance on object
             if (!$item->userHasClearance($cms_user, CLEARANCE_MODULE_VIEW)) {
                 return false;
             }
             //create email subject
             $parameters['item'] = $item;
             $parameters['public'] = true;
             $polymodParsing = new CMS_polymod_definition_parsing($params['emailSubject'], false);
             $subject = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
             $body = '';
             //create email body
             if ($params['emailBody']['type'] == 1) {
                 //send body
                 $parameters['module'] = CMS_poly_object_catalog::getModuleCodenameForField($this->_field->getID());
                 $polymodParsing = new CMS_polymod_definition_parsing($params['emailBody']['html'], true, CMS_polymod_definition_parsing::PARSE_MODE, $parameters['module']);
                 $body = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
             } elseif ($params['emailBody']['type'] == 2) {
                 //send a page
                 $page = CMS_tree::getPageById($params['emailBody']['pageID']);
                 if (!$page || $page->hasError()) {
                     $this->raiseError('Page ID is not a valid page : ' . $params['emailBody']['pageID']);
                     return false;
                 }
                 $pageHTMLFile = new CMS_file($page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM));
                 if (!$pageHTMLFile->exists()) {
                     $this->raiseError('Page HTML file does not exists : ' . $page->getHTMLURL(false, false, PATH_RELATIVETO_FILESYSTEM));
                     return false;
                 }
                 $body = $pageHTMLFile->readContent();
                 //create page URL call
                 $polymodParsing = new CMS_polymod_definition_parsing($params['emailBody']['pageURL'], false);
                 $pageURL = $polymodParsing->getContent(CMS_polymod_definition_parsing::OUTPUT_RESULT, $parameters);
                 parse_str($pageURL, $GLOBALS['_REQUEST']);
                 //$GLOBALS['_REQUEST']
                 //parse and eval HTML page
                 $cms_page_included = true;
                 $GLOBALS['cms_page_included'] = $cms_page_included;
                 //eval() the PHP code
                 $body = sensitiveIO::evalPHPCode($body);
                 $website = $page->getWebsite();
                 $webroot = $website->getURL();
                 //replace URLs values
                 $replace = array('="/' => '="' . $webroot . '/', "='/" => "='" . $webroot . "/", "url(/" => "url(" . $webroot . "/");
                 $body = str_replace(array_keys($replace), $replace, $body);
             } else {
                 $this->raiseError('No valid email type to send : ' . $params['emailBody']['type']);
                 return false;
             }
             if (isset($sendmail)) {
                 //$body .= print_r($sendmail,true);
             }
             //drop email sending
             if (isset($sendmail) && $sendmail === false) {
                 return false;
             }
             //if no body for email or if sendmail var is set to false, quit
             if (!$body) {
                 $this->raiseError('No email body to send ... Email parameters : user : '******'user'] . ' - object ' . $parameters['object']);
                 return false;
             }
             //This code is for debug purpose only.
             //$testFile = new CMS_file('/test/test_'.$cms_user->getUserId().'.php', CMS_file::WEBROOT);
             //$testFile->setContent($body);
             //$testFile->writeToPersistence();
             // Set email
             $email = new CMS_email();
             $email->setSubject($subject);
             $email->setEmailHTML($body);
             $email->setEmailTo($cms_user->getEmail());
             if ($params['includeFiles']) {
                 //check for file fields attached to object
                 $files = array();
                 $this->_getFieldsFiles($item, $files);
                 if (sizeof($files)) {
                     foreach ($files as $file) {
                         $email->setFile($file);
                     }
                 }
             }
             //set email From
             if (!$params['emailFrom']) {
                 $email->setFromName(APPLICATION_LABEL);
                 $email->setEmailFrom(APPLICATION_POSTMASTER_EMAIL);
             } else {
                 $email->setFromName($params['emailFrom']);
                 $email->setEmailFrom($params['emailFrom']);
             }
             //Send
             if ($email->sendEmail()) {
                 //store email sent number
                 $this->_subfieldValues[2]->setValue($this->_subfieldValues[2]->getValue() + 1);
                 $this->writeToPersistence();
                 return true;
             } else {
                 return false;
             }
             break;
         default:
             $this->raiseError('No valid task given : ' . $parameters['task']);
             return false;
             break;
     }
 }
Exemple #3
0
 /**
  * Submit pages to the regenerator. The first argument can either be a single page ID or an array of those.
  *
  * @param mixed $pages If it's a scalar, it's a page ID, else an array of pages IDs
  * @param integer $fromScratch Is the submission concerning a full from scratch regeneration (true) or a regeneration from linx files (false) ?
  * @param boolean $dontLaunchRegenerator to avoid multiple launch of the regenerator during multiple validation only the last page validation launch the script
  * @return void
  * @access public
  */
 static function submitToRegenerator($pages, $fromScratch, $dontLaunchRegenerator = false)
 {
     $fs = $fromScratch ? true : false;
     if (!is_array($pages)) {
         $pages = array($pages);
     }
     //get all scripts for standard module
     if (!class_exists('CMS_module_standard')) {
         CMS_grandFather::raiseError("Can not found standard module");
         return false;
     }
     $scripts = CMS_scriptsManager::getScripts(MOD_STANDARD_CODENAME);
     $pagesToRegen = array();
     foreach ($scripts as $scriptID => $script) {
         $pagesToRegen[$script['pageid']] = array('fromscratch' => $script['fromscratch'], 'script' => $scriptID);
     }
     foreach ($pages as $page) {
         if (isset($pagesToRegen[$page])) {
             //is existant script need to be updated ?
             $actual_fs = $pagesToRegen[$page]['fromscratch'];
             if (!$actual_fs && $fs) {
                 $parameters = array('pageid' => $page, 'fromscratch' => $fs);
                 CMS_scriptsManager::addScript(MOD_STANDARD_CODENAME, $parameters, $pagesToRegen[$page]['script']);
             }
         } else {
             //add script
             $parameters = array('pageid' => $page, 'fromscratch' => $fs);
             CMS_scriptsManager::addScript(MOD_STANDARD_CODENAME, $parameters);
         }
     }
     if (!$dontLaunchRegenerator) {
         //then, launch the regenerator script
         CMS_scriptsManager::startScript();
     }
 }