/** * Loads a list of predefined properties for the specicifies parameters, returns an array of Property\Predefined elements * * @return array */ public function load() { $properties = array(); $propertiesData = $this->db->fetchAll($this->model->getFilter(), $this->model->getOrder()); foreach ($propertiesData as $propertyData) { $properties[] = Config::getByName($propertyData["id"]); } $this->model->setNewsletter($properties); return $properties; }
public function sendTestAction() { $letter = Newsletter\Config::getByName($this->getParam("name")); $className = "\\Pimcore\\Model\\Object\\" . ucfirst($letter->getClass()); $object = $className::getByEmail($letter->getTestEmailAddress(), 1); if (!$object) { $objectList = $className . "\\Listing"; $list = new $objectList(); if ($letter->getObjectFilterSQL()) { $list->setCondition($letter->getObjectFilterSQL()); } $list->setOrderKey("RAND()", false); $list->setLimit(1); $list->setOffset(0); $object = current($list->load()); if (!$object) { throw new \Exception("no valid user data available, can't send email"); } } Tool\Newsletter::sendMail($letter, $object, $letter->getTestEmailAddress()); $this->_helper->json(array("success" => true)); }
protected function execute(InputInterface $input, OutputInterface $output) { $newsletter = Model\Tool\Newsletter\Config::getByName($input->getArgument("id")); if ($newsletter) { $pidFile = $newsletter->getPidFile(); if (file_exists($pidFile)) { \Logger::alert("Cannot send newsletters because there's already one active sending process"); exit; } $elementsPerLoop = 10; $objectList = "\\Pimcore\\Model\\Object\\" . ucfirst($newsletter->getClass()) . "\\Listing"; $list = new $objectList(); $conditions = array("(newsletterActive = 1 AND newsletterConfirmed = 1)"); if ($newsletter->getObjectFilterSQL()) { $conditions[] = $newsletter->getObjectFilterSQL(); } if ($newsletter->getPersonas()) { $class = Model\Object\ClassDefinition::getByName($newsletter->getClass()); if ($class && $class->getFieldDefinition("persona")) { $personas = array(); $p = explode(",", $newsletter->getPersonas()); if ($class->getFieldDefinition("persona") instanceof \Pimcore\Model\Object\ClassDefinition\Data\Persona) { foreach ($p as $value) { if (!empty($value)) { $personas[] = $list->quote($value); } } $conditions[] = "persona IN (" . implode(",", $personas) . ")"; } else { if ($class->getFieldDefinition("persona") instanceof \Pimcore\Model\Object\ClassDefinition\Data\Personamultiselect) { $personasCondition = array(); foreach ($p as $value) { $personasCondition[] = "persona LIKE " . $list->quote("%," . $value . ",%"); } $conditions[] = "(" . implode(" OR ", $personasCondition) . ")"; } } } } $list->setCondition(implode(" AND ", $conditions)); $list->setOrderKey("email"); $list->setOrder("ASC"); $elementsTotal = $list->getTotalCount(); $count = 0; $pidContents = array("start" => time(), "lastUpdate" => time(), "newsletter" => $newsletter->getName(), "total" => $elementsTotal, "current" => $count); $this->writePid($pidFile, $pidContents); for ($i = 0; $i < ceil($elementsTotal / $elementsPerLoop); $i++) { $list->setLimit($elementsPerLoop); $list->setOffset($i * $elementsPerLoop); $objects = $list->load(); foreach ($objects as $object) { try { $count++; \Logger::info("Sending newsletter " . $count . " / " . $elementsTotal . " [" . $newsletter->getName() . "]"); \Pimcore\Tool\Newsletter::sendMail($newsletter, $object, null, $input->getArgument("hostUrl")); $note = new Model\Element\Note(); $note->setElement($object); $note->setDate(time()); $note->setType("newsletter"); $note->setTitle("sent newsletter: '" . $newsletter->getName() . "'"); $note->setUser(0); $note->setData(array()); $note->save(); \Logger::info("Sent newsletter to: " . $this->obfuscateEmail($object->getEmail()) . " [" . $newsletter->getName() . "]"); } catch (\Exception $e) { \Logger::err($e); } } // check if pid exists if (!file_exists($pidFile)) { \Logger::alert("Newsletter PID not found, cancel sending process"); exit; } // update pid $pidContents["lastUpdate"] = time(); $pidContents["current"] = $count; $this->writePid($pidFile, $pidContents); \Pimcore::collectGarbage(); } // remove pid @unlink($pidFile); } else { \Logger::emerg("Newsletter '" . $input->getArgument("id") . "' doesn't exist"); } }
* Pimcore * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://www.pimcore.org/license * * @copyright Copyright (c) 2009-2014 pimcore GmbH (http://www.pimcore.org) * @license http://www.pimcore.org/license New BSD License */ chdir(__DIR__); include_once "startup.php"; use Pimcore\Model; $newsletter = Model\Tool\Newsletter\Config::getByName($argv[1]); if ($newsletter) { $pidFile = $newsletter->getPidFile(); if (file_exists($pidFile)) { \Logger::alert("Cannot send newsletters because there's already one active sending process"); exit; } $elementsPerLoop = 10; $objectList = "\\Pimcore\\Model\\Object\\" . ucfirst($newsletter->getClass()) . "\\Listing"; $list = new $objectList(); $conditions = array("(newsletterActive = 1 AND newsletterConfirmed = 1)"); if ($newsletter->getObjectFilterSQL()) { $conditions[] = $newsletter->getObjectFilterSQL(); } if ($newsletter->getPersonas()) { $class = Model\Object\ClassDefinition::getByName($newsletter->getClass());
// create legacy config folder $legacyFolder = PIMCORE_CONFIGURATION_DIRECTORY . "/LEGACY"; if (!is_dir($legacyFolder)) { mkdir($legacyFolder, 0777, true); } // NEWSLETTER $dir = PIMCORE_CONFIGURATION_DIRECTORY . "/newsletter"; if (is_dir($dir)) { $file = Pimcore\Config::locateConfigFile("newsletter.json"); $json = \Pimcore\Db\JsonFileTable::get($file); $json->truncate(); $files = scandir($dir); foreach ($files as $file) { if (strpos($file, ".xml")) { $name = str_replace(".xml", "", $file); $thumbnail = \Pimcore\Model\Tool\Newsletter\Config::getByName($name); $thumbnail = object2array($thumbnail); $thumbnail["id"] = $thumbnail["name"]; unset($thumbnail["name"]); $json->insertOrUpdate($thumbnail, $thumbnail["id"]); } } // move data rename($dir, $legacyFolder . "/newsletter"); } // TAG SNIPPET MANAGEMENT $dir = PIMCORE_CONFIGURATION_DIRECTORY . "/tags"; if (is_dir($dir)) { $file = Pimcore\Config::locateConfigFile("tag-manager.json"); $json = \Pimcore\Db\JsonFileTable::get($file); $json->truncate();