public function handleTask(&$context) { $adb = \PearDatabase::getInstance(); if (!getTabid('PDFMaker') || !vtlib_isModuleActive('PDFMaker')) { throw new \Exception('PDFMaker Extension not found!'); } /* Insert here source code to execute the task */ $recordChooser = $this->get('recordChooser'); if (empty($recordChooser) || $recordChooser == -1) { throw new \Exception('You need to configure the PDFMaker Integraion.'); } $recordIds = array(); if ($recordChooser === 'current') { $recordIds = array($context->getId()); $moduleName = $this->getModuleName(); } else { $currentTime = microtime(true); $benchmark = array(); $parts = explode("#~#", $this->get("search_module")); $related_module = VtUtils::getModuleName($parts[1]); $moduleName = $related_module; $logger = new \Workflow\ConditionLogger(); $objMySQL = new \Workflow\ConditionMysql($related_module, $context); $objMySQL->setLogger($logger); $main_module = \CRMEntity::getInstance($related_module); $sqlCondition = $objMySQL->parse($this->get("condition")); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $sqlTables = $objMySQL->generateTables(); if (strlen($sqlCondition) > 3) { $sqlCondition .= " AND vtiger_crmentity.deleted = 0"; } else { $sqlCondition .= " vtiger_crmentity.deleted = 0"; } $logs = $logger->getLogs(); $this->setStat($logs); $sqlCondition .= " GROUP BY vtiger_crmentity.crmid "; $idColumn = $main_module->table_name . "." . $main_module->table_index; $sqlQuery = "SELECT {$idColumn} as `idCol` " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : ""); $sortField = $this->get("sort_field"); if (!empty($sortField) && $sortField != -1) { $sortField = VtUtils::getColumnName($sortField); $sortDirection = $this->get("sortDirection"); $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection; } $this->addStat("MySQL Query: " . $sqlQuery); $result = $adb->query($sqlQuery, true); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $this->addStat("num Rows: " . $adb->num_rows($result)); # If no records are found, fo other way if ($adb->num_rows($result) == 0) { return "yes"; } $this->addStat("Benchmark: " . implode("/", $benchmark)); while ($row = $adb->fetchByAssoc($result)) { $recordIds[] = $row['idcol']; } } $context->save(); $useUser = Users::getActiveAdminUser(); $oldUser = vglobal('current_user'); vglobal('current_user', $useUser); $PDFMaker = new PDFMaker_PDFMaker_Model(); $dl = Vtiger_Language_Handler::getLanguage(); $mpdf = ""; $copies = $this->get('copies'); if ($copies == -1 || empty($copies)) { $copies = 1; } $templateids = array(); for ($i = 0; $i < $copies; $i++) { $templateids = array_merge($templateids, $this->get("template")); } $filename = $PDFMaker->GetPreparedMPDF($mpdf, $recordIds, $templateids, $moduleName, $dl, ''); if (strpos($filename, '.pdf') === false) { $filename .= '.pdf'; } // $filename = $PDFMaker->generate_cool_uri($filename); $tmpfile = tempnam(sys_get_temp_dir(), 'WfTmp'); @unlink($tmpfile); $mpdf->Output($tmpfile); $overwriteFilename = $this->get("filename", $context); if ($overwriteFilename != -1 && !empty($overwriteFilename)) { $filename = $overwriteFilename; } \Workflow\FileAction::doActions($this->get('resultaction'), $tmpfile, $filename, $context, $recordIds, $this->getWorkflow()); vglobal('current_user', $oldUser); return "yes"; }
public function handleTask(&$context) { $adb = \PearDatabase::getInstance(); /* Insert here source code to execute the task */ $currentTime = microtime(true); $benchmark = array(); $found_rows = $this->get("found_rows"); if (empty($found_rows) || $found_rows == -1) { $found_rows = 1; } $id = $this->get('recordid', $context); if (empty($id) || $id == -1 || !is_numeric($id)) { $targetContext = $context; } else { $targetContext = \Workflow\VTEntity::getForId($id); } $logger = new \Workflow\ConditionLogger(); $objMySQL = new \Workflow\ConditionMysql('Emails', $targetContext); $objMySQL->setLogger($logger); $sqlCondition = $objMySQL->parse($this->get("condition")); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $sqlTables = $objMySQL->generateTables(); //$sqlTables .= "\nLEFT JOIN vtiger_email_track ON(vtiger_email_track.crmid = vtiger_crmentity.crmid)"; if (strlen($sqlCondition) > 3) { $sqlCondition .= " AND vtiger_crmentity.deleted = 0 AND (vtiger_email_track.crmid IS NULL OR vtiger_email_track.crmid = " . $targetContext->getId() . ')'; } else { $sqlCondition .= " vtiger_crmentity.deleted = 0 AND (vtiger_email_track.crmid IS NULL OR vtiger_email_track.crmid = " . $targetContext->getId() . ')'; } $logs = $logger->getLogs(); $this->setStat($logs); $main_module = \CRMEntity::getInstance('Emails'); $sqlCondition .= " GROUP BY vtiger_crmentity.crmid "; $idColumn = $main_module->table_name . "." . $main_module->table_index; $sqlQuery = "SELECT {$idColumn} as `idCol`, vtiger_email_track.access_count as access_count " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : ""); $sortField = $this->get("sort_field"); if (!empty($sortField) && $sortField != -1) { $sortField = VtUtils::getColumnName($sortField); $sortDirection = $this->get("sortDirection"); $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection; } $numRows = $this->get("found_rows"); if (!empty($numRows) && $numRows != -1) { $sqlQuery .= " LIMIT " . $found_rows; } #var_dump(nl2br($sqlQuery));exit(); $this->addStat("MySQL Query: " . $sqlQuery); //echo $sqlQuery; $result = $adb->query($sqlQuery, true); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $this->addStat("num Rows: " . $adb->num_rows($result)); # If no records are found, fo other way if ($adb->num_rows($result) == 0) { return "not_found"; } while ($row = $adb->fetchByAssoc($result)) { if ($row['access_count'] > 0) { return 'yes'; } } return "no"; }
/** * @param $context \Workflow\VTEntity * @return string */ public function handleTask(&$context) { global $adb; if ($this->get("search_module") == -1) { return "no"; } $found_rows = $this->get("found_rows"); if (empty($found_rows) || $found_rows == -1) { $found_rows = 1; } $recordsource = $this->get('recordsource'); if (empty($recordsource) || $recordsource == -1) { $recordsource = 'condition'; } $parts = explode("#~#", $this->get("search_module")); $functionName = $parts[0]; $related_module = VtUtils::getModuleName($parts[1]); $recordids = array(); if ($recordsource == 'condition') { require_once 'modules/Workflow2/VTConditionMySql.php'; $logger = new \Workflow\ConditionLogger(); $objMySQL = new \Workflow\ConditionMysql($related_module, $context); $objMySQL->setLogger($logger); $main_module = CRMEntity::getInstance($related_module); #$sqlTables = $main_module->generateReportsQuery($related_module); $sqlCondition = $objMySQL->parse($this->get("condition")); $sqlTables = $objMySQL->generateTables(); if (strlen($sqlCondition) > 3) { $sqlCondition .= " AND vtiger_crmentity.deleted = 0"; } else { $sqlCondition .= " vtiger_crmentity.deleted = 0"; } $logs = $logger->getLogs(); $this->setStat($logs); $idColumn = $main_module->table_name . "." . $main_module->table_index; $sqlQuery = "SELECT {$idColumn} as `idCol` " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : ""); $sortField = $this->get("sort_field"); $sqlQuery .= ' GROUP BY crmid '; if (!empty($sortField) && $sortField != -1) { $sortDirection = $this->get("sortDirection"); $sortField = VtUtils::getColumnName($sortField); $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection; } $numRows = $this->get("found_rows"); if (!empty($numRows) && $numRows != -1) { $sqlQuery .= " LIMIT " . $found_rows; } $this->addStat("MySQL Query: " . $sqlQuery); $result = $adb->query($sqlQuery, true); $this->addStat("num Rows: " . $adb->num_rows($result)); while ($row = $adb->fetchByAssoc($result)) { $recordids[] = $row["idcol"]; } } if ($recordsource == 'customview') { $queryGenerator = new \QueryGenerator($related_module, \Users::getActiveAdminUser()); $queryGenerator->initForCustomViewById($this->get('customviewsource')); $query = $queryGenerator->getQuery(); $parts = preg_split('/FROM/i', $query); $sqlQuery = 'SELECT vtiger_crmentity.crmid as id_col FROM ' . $parts[1]; $result = $adb->query($sqlQuery, true); $this->addStat("num Rows: " . $adb->num_rows($result)); while ($row = $adb->fetchByAssoc($result)) { $recordids[] = $row["id_col"]; } } $filterbyproduct = $this->get('filterbyproduct'); if ($filterbyproduct === 'yes') { $products = $this->get('products'); if (!empty($products)) { $sql = 'SELECT id FROM vtiger_inventoryproductrel WHERE id IN (' . generateQuestionMarks($recordids) . ') AND productid = ? GROUP BY id'; $recordids[] = $products; $result = $adb->pquery($sql, $recordids); $recordids = array(); while ($row = $adb->fetchByAssoc($result)) { $recordids[] = $row['id']; } } } $workflow_id = $this->get("workflow_id"); if (!empty($workflow_id)) { foreach ($recordids as $recordId) { $tmpContext = \Workflow\VTEntity::getForId($recordId, $related_module); $tmpContext->clearEnvironment(); $tmpContext->loadEnvironment($context->getEnvironment()); $obj = new \Workflow\Main($workflow_id, false, $context->getUser()); $obj->setExecutionTrigger($this->getWorkflow()->getExecutionTrigger()); $obj->setContext($tmpContext); $obj->isSubWorkflow(true); $obj->start(); if ($obj->getSuccessRedirection() != false) { $this->getWorkflow()->setSuccessRedirection($obj->getSuccessRedirection()); $this->getWorkflow()->setSuccessRedirectionTarget($obj->getSuccessRedirectionTarget()); } $env = $this->get("env"); if ($env !== -1 && !empty($env["result_environments"])) { $oldEnv = $context->getEnvironment($env["result_environments"]); $oldEnv[] = $tmpContext->getEnvironment(); $context->setEnvironment("result_environments", $oldEnv, $this); } } } return "yes"; }
/** * @param $context \Workflow\VTEntity * @return string */ public function handleTask(&$context) { global $adb; $currentTime = microtime(true); $benchmark = array(); if ($this->get("search_module") == -1) { return "no"; } $found_rows = $this->get("found_rows"); if (empty($found_rows) || $found_rows == -1) { $found_rows = 1; } $parts = explode("#~#", $this->get("search_module")); $functionName = $parts[0]; $related_module = VtUtils::getModuleName($parts[1]); $logger = new \Workflow\ConditionLogger(); $objMySQL = new \Workflow\ConditionMysql($related_module, $context); $objMySQL->setLogger($logger); $main_module = \CRMEntity::getInstance($related_module); #$sqlTables = $main_module->generateReportsQuery($related_module); if ($related_module == "Calendar") { #$sqlTables .= " LEFT JOIN vtiger_seactivityrel ON(vtiger_seactivityrel.activityid = vtiger_crmentity.crmid)"; } $sqlCondition = $objMySQL->parse($this->get("condition")); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $sqlTables = $objMySQL->generateTables(); if (strlen($sqlCondition) > 3) { $sqlCondition .= " AND vtiger_crmentity.deleted = 0"; } else { $sqlCondition .= " vtiger_crmentity.deleted = 0"; } $logs = $logger->getLogs(); $this->setStat($logs); $sqlCondition .= " GROUP BY vtiger_crmentity.crmid "; $idColumn = $main_module->table_name . "." . $main_module->table_index; $sqlQuery = "SELECT {$idColumn} as `idCol` " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : ""); $sortField = $this->get("sort_field"); if (!empty($sortField) && $sortField != -1) { $sortField = VtUtils::getColumnName($sortField); $sortDirection = $this->get("sortDirection"); $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection; } $numRows = $this->get("found_rows"); if (!empty($numRows) && $numRows != -1) { $sqlQuery .= " LIMIT " . $found_rows; } #var_dump(nl2br($sqlQuery));exit(); $this->addStat("MySQL Query: " . $sqlQuery); $result = $adb->query($sqlQuery); $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $this->addStat("num Rows: " . $adb->num_rows($result)); # If no records are found, fo other way if ($adb->num_rows($result) == 0) { return "no"; } $environment = $context->getEnvironment(); while ($row = $adb->fetchByAssoc($result)) { $expression = $this->get("expression"); if (!empty($expression)) { $tmpContext = \Workflow\VTEntity::getForId($row["idcol"], $related_module); $tmpContext->loadEnvironment($environment); $parser = new \Workflow\ExpressionParser($expression, $tmpContext, false); # Last Parameter = DEBUG try { $parser->run(); } catch (ExpressionException $exp) { Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", ""); } $environment = $tmpContext->getEnvironment(); } } # while $newTime = microtime(true); $benchmark[] = round($newTime - $currentTime, 3); $currentTime = $newTime; $context->loadEnvironment($environment); $this->addStat("Benchmark: " . implode("/", $benchmark)); return "yes"; }