public function index() { $fingerprint = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum'); $identity = $this->getIdentity(); if (!empty($identity->id)) { $identity = $identity->reload(); $fingerprints = (array) $identity->{'affiliates.fingerprints'}; // is this a new fingerprint? if (!in_array($fingerprint, $fingerprints)) { $fingerprints[] = $fingerprint; $identity->{'affiliates.fingerprints'} = $fingerprints; $identity->save(); // is the user an affiliate? if so, add their fingerprint to all of their referrals $update = \Affiliates\Models\Referrals::collection()->update(array('affiliate_id' => $identity->id), array('$addToSet' => array('affiliate_fingerprints' => $fingerprint)), array('multiple' => true)); \Dsc\Queue::task('\\Affiliates\\Models\\Referrals::checkFingerprints', array('id' => $identity->id), array('title' => 'Checking browser fingerprints in referrals from affiliate: ' . $identity->fullName())); // is the user a referral? if so, add the fingerprint to their referral record if ($referral = \Affiliates\Models\Referrals::isUser($identity->id)) { $fingerprints = (array) $referral->referral_fingerprints; if (!in_array($fingerprint, $fingerprints)) { $fingerprints[] = $fingerprint; $referral->referral_fingerprints = $fingerprints; try { $referral->verifyFingerprint()->save(); } catch (\Exception $e) { $referral->log($e->getMessage(), 'ERROR', 'Affiliates\\Site\\Controllers\\Fingerprint.saveReferral'); } } } } } else { } }
protected function afterCreate() { if (!empty($this->__email_recipient)) { \Dsc\Queue::task('\\Shop\\Models\\OrderedGiftCards::queueEmailNewGiftCard', array('card_id' => $this->id, 'recipients' => array($this->__email_recipient))); } parent::afterCreate(); }
/** * Finds all carts that are abandoned and adds jobs for email notifications to queue manager */ public static function queueEmailsForNewlyAbandonedCarts() { $settings = \Shop\Models\Settings::fetch(); if (empty($settings->abandoned_cart_emails_enabled)) { return; } $notifications = (array) $settings->get('abandoned_cart_emails'); if (empty($notifications)) { return; } $newly_abandoned = (new static())->setState('filter.abandoned', '1')->setState('filter.abandoned_only_new', '1')->getList(); if (count((array) $newly_abandoned)) { $abandoned_time = $settings->get('abandoned_cart_time') * 60; foreach ($newly_abandoned as $cart) { $email = null; if ($cart->quantity() > 0) { if ($cart->user()->guest) { // don't send emails to guest users continue; } $email = $cart->user_email ? $cart->user_email : $cart->user()->email(); $cart->abandoned_notifications = array(); foreach ($notifications as $idx => $val) { // scheduling should be relative to when this job runs, not the time of the cart's last modification, // because that could lead to lots of emails at once for really old carts // if the cron job is started months after the site goes live $time = $abandoned_time + time() + $val['delay'] * 60; $task = \Dsc\Queue::task('\\Shop\\Models\\CartsAbandoned::sendAbandonedEmailNotification', array((string) $cart->id, (string) $idx), array('title' => 'Abandoned Cart Email Notification to ' . $email, 'when' => $time)); $cart->abandoned_notifications[] = new \MongoId((string) $task->_id); } // save reference to those task to the cart without modifying last_modified timestamp $cart->store(); } } } }
public function afterSaveUsersModelsUsers($event) { $identity = $event->getArgument('model'); // if the active status of the user record from the DB (grabbed in beforeSave above) // differs from the active status of the $user, and $user->active = true // grant the affiliate a referral credit if (!empty($this->db_user)) { if ($affiliate_id = $this->db_user->{'affiliates.validation_triggers_referral'}) { // Make the user into a referral for affiliate_id // \Dsc\System::addMessage('Making you into a referral for an Affiliate ID'); try { $referral = \Affiliates\Models\Referrals::isUser($identity->id); if (empty($referral->id)) { // is this a valid affiliate? $affiliate = (new \Users\Models\Users())->load(array('_id' => new \MongoId((string) $affiliate_id))); if (!empty($affiliate->id)) { // make them into a referral $referral = new \Affiliates\Models\Referrals(); $referral->bind(array('referral_user_id' => $identity->id, 'referral_name' => $identity->fullName(), 'referral_email' => $identity->email, 'referral_fingerprints' => (array) $identity->{'affiliates.fingerprints'}, 'affiliate_fingerprints' => (array) $affiliate->{'affiliates.fingerprints'}, 'affiliate_id' => $affiliate_id))->save(); /* \Affiliates\Models\Referrals::createCommission($referral->id); */ \Dsc\Queue::task('\\Affiliates\\Models\\Referrals::createCommission', array('id' => $referral->id), array('title' => 'Verify and create commission for referral: ' . $referral->referral_email)); } } // referral created, clear it from the user $identity->{'affiliates.validation_triggers_referral'} = null; $identity->{'affiliates.validation_triggers_referral_invite'} = null; $identity = $identity->store(); } catch (\Exception $e) { // Log the failure in the system logger $identity->log('Could not create referral for affiliate ' . $affiliate_id . ' (' . $affiliate->email . ') for referral of user ' . $identity->id . ' (' . $identity->email . ') because of error ' . $e->getMessage()); $identity->{'affiliates.validation_triggers_referral'} = null; $identity->{'affiliates.validation_triggers_referral_invite'} = null; $identity = $identity->store(); } } elseif ($invite_id = $this->db_user->{'affiliates.validation_triggers_referral_invite'}) { try { if ($invite = \Affiliates\Models\Invites::idValid($invite_id)) { $affiliate = (new \Users\Models\Users())->load(array('_id' => new \MongoId((string) $invite->affiliate_id))); if (!empty($affiliate->id)) { // make them into a referral $referral = new \Affiliates\Models\Referrals(); $referral->bind(array('referral_user_id' => $identity->id, 'referral_name' => $identity->fullName(), 'referral_email' => $invite->recipient_email, 'referral_fingerprints' => (array) $identity->{'affiliates.fingerprints'}, 'affiliate_fingerprints' => (array) $affiliate->{'affiliates.fingerprints'}, 'affiliate_id' => $invite->affiliate_id, 'affiliate_email' => $affiliate->email, 'invite_id' => $invite_id))->save(); /* \Affiliates\Models\Referrals::createCommission($referral->id); */ \Dsc\Queue::task('\\Affiliates\\Models\\Referrals::createCommission', array('id' => $referral->id), array('title' => 'Verify and create commission for referral: ' . $referral->referral_email)); } // referral created, clear it from the user $identity->{'affiliates.validation_triggers_referral'} = null; $identity->{'affiliates.validation_triggers_referral_invite'} = null; $identity = $identity->store(); } } catch (\Exception $e) { // Log the failure in the system logger $identity->log('Could not create referral for invite ' . $invite_id . ' for referral of user ' . $identity->id . ' (' . $identity->email . ') because of error ' . $e->getMessage()); $identity->{'affiliates.validation_triggers_referral'} = null; $identity->{'affiliates.validation_triggers_referral_invite'} = null; $identity = $identity->store(); } } } }
public function handleTraditional() { $app = \Base::instance(); $files_path = $app->get('TEMP') . "files"; $chunks_path = $app->get('TEMP') . "chunks"; if (!file_exists($chunks_path)) { mkdir($chunks_path, \Base::MODE, true); } if (!file_exists($files_path)) { mkdir($files_path, \Base::MODE, true); } $uploader = new \Fineuploader\Traditional\Handler(); // Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp") $uploader->allowedExtensions = array(); // all files types allowed by default // Specify max file size in bytes. $uploader->sizeLimit = 10 * 1024 * 1024; // default is 10 MiB // Specify the input name set in the javascript. $uploader->inputName = "qqfile"; // matches Fine Uploader's default inputName value by default // If you want to use the chunking/resume feature, specify the folder to temporarily save parts. $uploader->chunksFolder = $chunks_path; $method = $_SERVER["REQUEST_METHOD"]; if ($method == "POST") { header("Content-Type: text/plain"); // Call handleUpload() with the name of the folder, relative to PHP's getcwd() $result = $uploader->handleUpload($files_path); // To return a name used for uploaded file you can use the following line. $result["uploadName"] = $uploader->getUploadName(); $result["originalName"] = $uploader->getName(); // was upload successful? if (!empty($result['success'])) { // OK, we have the file in the tmp folder, let's now fire up the assets model and save it to Mongo $model = $this->getModel(); $db = $model->getDb(); $grid = $model->collectionGridFS(); // The file's location in the File System $filename = $result["uploadName"]; $pathinfo = pathinfo($filename); $buffer = file_get_contents($files_path . "/" . $filename); $originalname = $result["originalName"]; $pathinfo_original = pathinfo($originalname); $thumb = null; if ($thumb_binary_data = $model->getThumb($buffer, $pathinfo['extension'])) { $thumb = new \MongoBinData($thumb_binary_data, 2); } $values = array('storage' => 'gridfs', 'contentType' => $model->getMimeType($buffer), 'md5' => md5_file($files_path . "/" . $filename), 'thumb' => $thumb, 'url' => null, "title" => \Dsc\String::toSpaceSeparated($model->inputfilter()->clean($originalname)), "filename" => $originalname); if (empty($values['title'])) { $values['title'] = $values['md5']; } // save the file if ($storedfile = $grid->storeFile($files_path . "/" . $filename, $values)) { $model->load(array('_id' => $storedfile)); $model->bind($values); $model->{'slug'} = $model->generateSlug(); $model->save(); } // $storedfile has newly stored file's Document ID $result["asset_id"] = (string) $storedfile; $result["slug"] = $model->{'slug'}; \Dsc\Queue::task('\\Assets\\Models\\Storage\\CloudFiles::gridfstoCDN', array($result['asset_id'])); } echo json_encode($result); } else { header("HTTP/1.0 405 Method Not Allowed"); } }
public static function throttledCleanup() { $settings = \Support\Models\Settings::fetch(); if (empty($settings->last_sessions_cleanup) || $settings->last_sessions_cleanup < time() - 900) { $settings->last_sessions_cleanup = time(); if (empty($settings->id)) { $settings->save(); } else { $settings->store(); } \Dsc\Queue::task('\\Support\\Models\\ChatSessions::cleanup'); return true; } return null; }
<?php define('PATH_ROOT', realpath(__DIR__ . '/../../../../../../') . '/'); //AUTOLOAD all your composer libraries now. @(include_once realpath(__DIR__ . '/../../../../../../') . '/vendor/autoload.php') or die("You need to run php composer.phar install for your application to run."); //Require FatFree Base Library https://github.com/bcosca/fatfree $app = Base::instance(); $app->set('PATH_ROOT', PATH_ROOT); $app->set('AUTOLOAD', $app->get('PATH_ROOT') . 'apps/;'); //require $app->get('PATH_ROOT') . 'vendor/autoload.php'; $app->set('APP_NAME', 'cli'); require $app->get('PATH_ROOT') . 'config/config.php'; // bootstap each mini-app \Dsc\Apps::instance()->bootstrap(); // process the queue! \Dsc\Queue::process('local');
<?php define('PATH_ROOT', realpath(__DIR__ . '/../../../../../../') . '/'); //AUTOLOAD all your composer libraries now. @(include_once realpath(__DIR__ . '/../../../../../../') . '/vendor/autoload.php') or die("You need to run php composer.phar install for your application to run."); //Require FatFree Base Library https://github.com/bcosca/fatfree $app = Base::instance(); $app->set('PATH_ROOT', PATH_ROOT); $app->set('AUTOLOAD', $app->get('PATH_ROOT') . 'apps/;'); //require $app->get('PATH_ROOT') . 'vendor/autoload.php'; $app->set('APP_NAME', 'cli'); require $app->get('PATH_ROOT') . 'config/config.php'; // bootstap each mini-app \Dsc\Apps::instance()->bootstrap(); // process the queue! \Dsc\Queue::process();
public static function queueEmailForOrder(\Shop\Models\Orders $order) { $settings = \Shop\Models\Settings::fetch(); if (empty($settings->{'reviews.enabled'})) { return; } $days_from_now = $settings->{'reviews.email_days'}; if (empty($days_from_now)) { return; } $email = $order->user_email; // Schedule the email to be sent $days_from_now $days_from_now = abs($days_from_now); $time = time() + $days_from_now * 86400; $task = \Dsc\Queue::task('\\Shop\\Models\\ProductReviews::sendEmailForOrder', array((string) $order->id), array('title' => 'Request product reviews from ' . $email . ' for order ' . $order->id, 'when' => $time, 'email' => $email)); }