protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection(); $sql = 'SELECT id FROM member WHERE is_active != 0'; $where = array(); if ( $options['min'] && $options['max'] && $options['min'] <= $options['max']) { $sql .= ' AND id BETWEEN ? AND ?'; $where = array(intval($options['min']),intval($options['max'])); } $memberIds = $this->conn->fetchColumn($sql, $where); foreach ($memberIds as $memberid) { for ($i=0; $i<$options['number']; ++$i) { $ac = new ActivityData(); $ac->setMemberId($memberid); $ac->setBody(md5($i)); $ac->setPublicFlag(1); $ac->save(); $ac->free(); $this->logSection('posted a activity', sprintf('%s', $memberid)); } } }
public function updateActivity($memberId, $body, $options = array()) { $object = new ActivityData(); $object->setMemberId($memberId); $object->setBody($body); if (isset($options['public_flag'])) { $publicFlagKeys = array_keys($this->getPublicFlags(false)); if (!in_array($options['public_flag'], $publicFlagKeys)) { throw new LogicException('Invalid public flag'); } $object->setPublicFlag($options['public_flag']); } if (isset($options['in_reply_to_activity_id'])) { $object->setInReplyToActivityId($options['in_reply_to_activity_id']); } if (isset($options['is_pc']) && !$options['is_pc']) { $object->setIsPc(false); } if (isset($options['is_mobile']) && !$options['is_mobile']) { $object->setIsMobile(false); } if (isset($options['uri'])) { $object->setUri($options['uri']); } if (isset($options['source'])) { $object->setSource($options['source']); if (isset($options['source_uri'])) { $object->setSourceUri($options['source_uri']); } } $activityImages = array(); if (isset($options['images'])) { if (!is_array($options['images'])) { $options['images'] = array($options['images']); } foreach ($options['images'] as $image) { $activityImage = new ActivityImage(); if (isset($image['file_id'])) { $activityImage->setFileId($image['file_id']); } elseif (isset($image['uri']) && isset($image['mime_type'])) { $activityImage->setUri($image['uri']); $activityImage->setMimeType($image['mime_type']); } else { throw new LogicException('Invalid image data'); } $activityImages[] = $activityImage; } } if (isset($options['foreign_table']) && isset($options['foreign_id'])) { $object->setForeignTable($options['foreign_table']); $object->setForeignId($options['foreign_id']); } $object->save(); foreach ($activityImages as $activityImage) { $activityImage->setActivityData($object); $activityImage->save(); } return $object; }
public function executePost(sfWebRequest $request) { $form = new sfForm(); $token = $form->getCSRFToken(); if ($token = !$request->getParameter('CSRFtoken')) { $json = array('status' => 'error', 'message' => 'Error. Invalid CSRF token Key.'); return $this->renderText(json_encode($json)); } if (!$request->getParameter('body')) { $json = array('status' => 'error', 'message' => 'Error. Body is null.'); return $this->renderText(json_encode($json)); } $activity = new ActivityData(); $activity->setMemberId($this->getUser()->getMemberId()); $activity->setBody($request->getParameter('body')); $mentions = opTimelinePluginUtil::hasScreenName($request->getParameter('body')); if (!is_null($mentions)) { $activity->setTemplate('mention_member_id'); $activity->setTemplateParam($mentions); } $inReplyToActivityId = $request->getParameter('replyId'); if (isset($inReplyToActivityId) && is_numeric($inReplyToActivityId)) { $activity->setInReplyToActivityId($inReplyToActivityId); } $foreign = $request->getParameter('foreign'); $foreignId = $request->getParameter('foreignId'); if (isset($foreign) && isset($foreignId) && is_numeric($foreignId)) { $activity->setForeignTable($foreign); $activity->setForeignId($foreignId); } $activity->setPublicFlag(1); $activity->save(); $json = array('status' => 'success', 'message' => 'UPDATE was succeed!'); return $this->renderText(json_encode($json)); }
public function executePost(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); if ($token = !$request->getParameter('body')) { $this->status = 'error'; $this->message = 'Error. Body is null.'; return sfView::SUCCESS; } $activity = new ActivityData(); $activity->setMemberId($this->getMember()->getId()); $activity->setBody(htmlspecialchars($request->getParameter('body'), ENT_QUOTES)); $mentions = opTimelinePluginUtil::hasScreenName($request->getParameter('body')); if (!is_null($mentions)) { $activity->setTemplate('mention_member_id'); $activity->setTemplateParam($mentions); } $inReplyToActivityId = $request->getParameter('replyId'); if (isset($inReplyToActivityId) && is_numeric($inReplyToActivityId)) { $activity->setInReplyToActivityId($inReplyToActivityId); } $foreign = $request->getParameter('foreign'); $foreignId = $request->getParameter('foreignId'); if (isset($foreign) && isset($foreignId) && is_numeric($foreignId)) { $activity->setForeignTable($foreign); $activity->setForeignId($foreignId); } $activity->setPublicFlag(1); $activity->save(); $this->status = 'success'; $this->message = "Update request was suceed!"; return sfView::SUCCESS; }