public function loadPage() { $table = new PhabricatorMetaMTAMailingList(); $conn_r = $table->establishConnection('r'); $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); return $table->loadAllFromArray($data); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $offset = $request->getInt('offset', 0); $pager = new AphrontPagerView(); $pager->setPageSize(1000); $pager->setOffset($offset); $pager->setURI($request->getRequestURI(), 'offset'); $list = new PhabricatorMetaMTAMailingList(); $conn_r = $list->establishConnection('r'); $data = queryfx_all($conn_r, 'SELECT * FROM %T ORDER BY name ASC LIMIT %d, %d', $list->getTableName(), $pager->getOffset(), $pager->getPageSize() + 1); $data = $pager->sliceResults($data); $lists = $list->loadAllFromArray($data); $rows = array(); foreach ($lists as $list) { $rows[] = array(phutil_escape_html($list->getPHID()), phutil_escape_html($list->getEmail()), phutil_escape_html($list->getName()), phutil_render_tag('a', array('class' => 'button grey small', 'href' => '/mail/lists/edit/' . $list->getID() . '/'), 'Edit')); } $table = new AphrontTableView($rows); $table->setHeaders(array('PHID', 'Email', 'Name', '')); $table->setColumnClasses(array(null, null, 'wide', 'action')); $panel = new AphrontPanelView(); $panel->appendChild($table); $panel->setHeader('Mailing Lists'); $panel->setCreateButton('Add New List', '/mail/lists/edit/'); $panel->appendChild($pager); return $this->buildStandardPageResponse($panel, array('title' => 'Mailing Lists', 'tab' => 'lists')); }
public function processRequest() { if ($this->id) { $list = id(new PhabricatorMetaMTAMailingList())->load($this->id); if (!$list) { return new Aphront404Response(); } } else { $list = new PhabricatorMetaMTAMailingList(); } $e_email = true; $e_uri = null; $e_name = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { $list->setName($request->getStr('name')); $list->setEmail($request->getStr('email')); $list->setURI($request->getStr('uri')); $e_email = null; $e_name = null; if (!strlen($list->getEmail())) { $e_email = 'Required'; $errors[] = 'Email is required.'; } if (!strlen($list->getName())) { $e_name = 'Required'; $errors[] = 'Name is required.'; } else { if (preg_match('/[ ,]/', $list->getName())) { $e_name = 'Invalid'; $errors[] = 'Name must not contain spaces or commas.'; } } if ($list->getURI()) { if (!PhabricatorEnv::isValidWebResource($list->getURI())) { $e_uri = 'Invalid'; $errors[] = 'Mailing list URI must point to a valid web page.'; } } if (!$errors) { try { $list->save(); return id(new AphrontRedirectResponse())->setURI('/mail/lists/'); } catch (AphrontQueryDuplicateKeyException $ex) { $e_email = 'Duplicate'; $errors[] = 'Another mailing list already uses that address.'; } } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($list->getID()) { $form->setAction('/mail/lists/edit/' . $list->getID() . '/'); } else { $form->setAction('/mail/lists/edit/'); } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setValue($list->getEmail())->setCaption('Email will be delivered to this address.')->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setError($e_name)->setCaption('Human-readable display and autocomplete name.')->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel('URI')->setName('uri')->setError($e_uri)->setCaption('Optional link to mailing list archives or info.')->setValue($list->getURI()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue(nonempty($list->getID(), '-')))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setValue(nonempty($list->getPHID(), '-')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/mail/lists/')); $panel = new AphrontPanelView(); if ($list->getID()) { $panel->setHeader('Edit Mailing List'); } else { $panel->setHeader('Create New Mailing List'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Mailing List')); }
public function loadHandles() { $types = phid_group_by_type($this->phids); $handles = array(); $external_loaders = PhabricatorEnv::getEnvConfig('phid.external-loaders'); foreach ($types as $type => $phids) { switch ($type) { case PhabricatorPHIDConstants::PHID_TYPE_MAGIC: // Black magic! foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); switch ($phid) { case ManiphestTaskOwner::OWNER_UP_FOR_GRABS: $handle->setName('Up For Grabs'); $handle->setFullName('upforgrabs (Up For Grabs)'); $handle->setComplete(true); break; case ManiphestTaskOwner::PROJECT_NO_PROJECT: $handle->setName('No Project'); $handle->setFullName('noproject (No Project)'); $handle->setComplete(true); break; default: $handle->setName('Foul Magicks'); break; } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_USER: $object = new PhabricatorUser(); $users = $object->loadAllWhere('phid IN (%Ls)', $phids); $users = mpull($users, null, 'getPHID'); $image_phids = mpull($users, 'getProfileImagePHID'); $image_phids = array_unique(array_filter($image_phids)); $images = array(); if ($image_phids) { $images = id(new PhabricatorFile())->loadAllWhere('phid IN (%Ls)', $image_phids); $images = mpull($images, 'getBestURI', 'getPHID'); } $statuses = id(new PhabricatorUserStatus())->loadCurrentStatuses($phids); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($users[$phid])) { $handle->setName('Unknown User'); } else { $user = $users[$phid]; $handle->setName($user->getUsername()); $handle->setURI('/p/' . $user->getUsername() . '/'); $handle->setFullName($user->getUsername() . ' (' . $user->getRealName() . ')'); $handle->setAlternateID($user->getID()); $handle->setComplete(true); if (isset($statuses[$phid])) { $handle->setStatus($statuses[$phid]->getTextStatus()); } $handle->setDisabled($user->getIsDisabled()); $img_uri = idx($images, $user->getProfileImagePHID()); if ($img_uri) { $handle->setImageURI($img_uri); } else { $handle->setImageURI(PhabricatorUser::getDefaultProfileImageURI()); } } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_MLST: $object = new PhabricatorMetaMTAMailingList(); $lists = $object->loadAllWhere('phid IN (%Ls)', $phids); $lists = mpull($lists, null, 'getPHID'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($lists[$phid])) { $handle->setName('Unknown Mailing List'); } else { $list = $lists[$phid]; $handle->setName($list->getName()); $handle->setURI($list->getURI()); $handle->setFullName($list->getName()); $handle->setComplete(true); } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_DREV: $object = new DifferentialRevision(); $revs = $object->loadAllWhere('phid in (%Ls)', $phids); $revs = mpull($revs, null, 'getPHID'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($revs[$phid])) { $handle->setName('Unknown Revision'); } else { $rev = $revs[$phid]; $handle->setName($rev->getTitle()); $handle->setURI('/D' . $rev->getID()); $handle->setFullName('D' . $rev->getID() . ': ' . $rev->getTitle()); $handle->setComplete(true); $status = $rev->getStatus(); if ($status == ArcanistDifferentialRevisionStatus::CLOSED || $status == ArcanistDifferentialRevisionStatus::ABANDONED) { $closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; $handle->setStatus($closed); } } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_CMIT: $object = new PhabricatorRepositoryCommit(); $commits = $object->loadAllWhere('phid in (%Ls)', $phids); $commits = mpull($commits, null, 'getPHID'); $repository_ids = array(); $callsigns = array(); if ($commits) { $repository_ids = mpull($commits, 'getRepositoryID'); $repositories = id(new PhabricatorRepository())->loadAllWhere('id in (%Ld)', array_unique($repository_ids)); $callsigns = mpull($repositories, 'getCallsign'); } foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($commits[$phid]) || !isset($callsigns[$repository_ids[$phid]])) { $handle->setName('Unknown Commit'); } else { $commit = $commits[$phid]; $callsign = $callsigns[$repository_ids[$phid]]; $repository = $repositories[$repository_ids[$phid]]; $commit_identifier = $commit->getCommitIdentifier(); // In case where the repository for the commit was deleted, // we don't have have info about the repository anymore. if ($repository) { $name = $repository->formatCommitName($commit_identifier); $handle->setName($name); } else { $handle->setName('Commit ' . 'r' . $callsign . $commit_identifier); } $handle->setURI('/r' . $callsign . $commit_identifier); $handle->setFullName('r' . $callsign . $commit_identifier); $handle->setTimestamp($commit->getEpoch()); $handle->setComplete(true); } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_TASK: $object = new ManiphestTask(); $tasks = $object->loadAllWhere('phid in (%Ls)', $phids); $tasks = mpull($tasks, null, 'getPHID'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($tasks[$phid])) { $handle->setName('Unknown Revision'); } else { $task = $tasks[$phid]; $handle->setName($task->getTitle()); $handle->setURI('/T' . $task->getID()); $handle->setFullName('T' . $task->getID() . ': ' . $task->getTitle()); $handle->setComplete(true); $handle->setAlternateID($task->getID()); if ($task->getStatus() != ManiphestTaskStatus::STATUS_OPEN) { $closed = PhabricatorObjectHandleStatus::STATUS_CLOSED; $handle->setStatus($closed); } } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_FILE: $object = new PhabricatorFile(); $files = $object->loadAllWhere('phid IN (%Ls)', $phids); $files = mpull($files, null, 'getPHID'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($files[$phid])) { $handle->setName('Unknown File'); } else { $file = $files[$phid]; $handle->setName($file->getName()); $handle->setURI($file->getBestURI()); $handle->setComplete(true); } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_PROJ: $object = new PhabricatorProject(); $projects = $object->loadAllWhere('phid IN (%Ls)', $phids); $projects = mpull($projects, null, 'getPHID'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($projects[$phid])) { $handle->setName('Unknown Project'); } else { $project = $projects[$phid]; $handle->setName($project->getName()); $handle->setURI('/project/view/' . $project->getID() . '/'); $handle->setComplete(true); } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_REPO: $object = new PhabricatorRepository(); $repositories = $object->loadAllWhere('phid in (%Ls)', $phids); $repositories = mpull($repositories, null, 'getPHID'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($repositories[$phid])) { $handle->setName('Unknown Repository'); } else { $repository = $repositories[$phid]; $handle->setName($repository->getCallsign()); $handle->setURI('/diffusion/' . $repository->getCallsign() . '/'); $handle->setComplete(true); } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_OPKG: $object = new PhabricatorOwnersPackage(); $packages = $object->loadAllWhere('phid in (%Ls)', $phids); $packages = mpull($packages, null, 'getPHID'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($packages[$phid])) { $handle->setName('Unknown Package'); } else { $package = $packages[$phid]; $handle->setName($package->getName()); $handle->setURI('/owners/package/' . $package->getID() . '/'); $handle->setComplete(true); } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_APRJ: $project_dao = new PhabricatorRepositoryArcanistProject(); $projects = $project_dao->loadAllWhere('phid IN (%Ls)', $phids); $projects = mpull($projects, null, 'getPHID'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($projects[$phid])) { $handle->setName('Unknown Arcanist Project'); } else { $project = $projects[$phid]; $handle->setName($project->getName()); $handle->setComplete(true); } $handles[$phid] = $handle; } break; case PhabricatorPHIDConstants::PHID_TYPE_WIKI: $document_dao = new PhrictionDocument(); $content_dao = new PhrictionContent(); $conn = $document_dao->establishConnection('r'); $documents = queryfx_all($conn, 'SELECT * FROM %T document JOIN %T content ON document.contentID = content.id WHERE document.phid IN (%Ls)', $document_dao->getTableName(), $content_dao->getTableName(), $phids); $documents = ipull($documents, null, 'phid'); foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setPHID($phid); $handle->setType($type); if (empty($documents[$phid])) { $handle->setName('Unknown Document'); } else { $info = $documents[$phid]; $handle->setName($info['title']); $handle->setURI(PhrictionDocument::getSlugURI($info['slug'])); $handle->setComplete(true); } $handles[$phid] = $handle; } break; default: $loader = null; if (isset($external_loaders[$type])) { $loader = $external_loaders[$type]; } else { if (isset($external_loaders['*'])) { $loader = $external_loaders['*']; } } if ($loader) { $object = newv($loader, array()); $handles += $object->loadHandles($phids); break; } foreach ($phids as $phid) { $handle = new PhabricatorObjectHandle(); $handle->setType($type); $handle->setPHID($phid); $handle->setName('Unknown Object'); $handle->setFullName('An Unknown Object'); $handles[$phid] = $handle; } break; } } return $handles; }
public function processRequest() { if ($this->id) { $list = id(new PhabricatorMetaMTAMailingList())->load($this->id); if (!$list) { return new Aphront404Response(); } } else { $list = new PhabricatorMetaMTAMailingList(); } $e_email = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { $list->setName($request->getStr('name')); $list->setEmail($request->getStr('email')); $list->setURI($request->getStr('uri')); if (!strlen($list->getEmail())) { $e_email = 'Required'; $errors[] = 'Email is required.'; } if (!$errors) { $list->save(); return id(new AphrontRedirectResponse())->setURI('/mail/lists/'); } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($list->getID()) { $form->setAction('/mail/lists/edit/' . $list->getID() . '/'); } else { $form->setAction('/mail/lists/edit/'); } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setValue($list->getEmail())->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel('URI')->setName('uri')->setValue($list->getURI()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue(nonempty($list->getID(), '-')))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setValue(nonempty($list->getPHID(), '-')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/mail/lists/')); $panel = new AphrontPanelView(); if ($list->getID()) { $panel->setHeader('Edit Mailing List'); } else { $panel->setHeader('Create New Mailing List'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Mailing List')); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); if ($this->id) { $page_title = pht('Edit Mailing List'); $list = id(new PhabricatorMailingListQuery())->setViewer($viewer)->withIDs(array($this->id))->executeOne(); if (!$list) { return new Aphront404Response(); } } else { $page_title = pht('Create Mailing List'); $list = new PhabricatorMetaMTAMailingList(); } $e_email = true; $e_uri = null; $e_name = true; $errors = array(); $crumbs = $this->buildApplicationCrumbs(); if ($request->isFormPost()) { $list->setName($request->getStr('name')); $list->setEmail($request->getStr('email')); $list->setURI($request->getStr('uri')); $e_email = null; $e_name = null; if (!strlen($list->getEmail())) { $e_email = pht('Required'); $errors[] = pht('Email is required.'); } if (!strlen($list->getName())) { $e_name = pht('Required'); $errors[] = pht('Name is required.'); } else { if (preg_match('/[ ,]/', $list->getName())) { $e_name = pht('Invalid'); $errors[] = pht('Name must not contain spaces or commas.'); } } if ($list->getURI()) { if (!PhabricatorEnv::isValidWebResource($list->getURI())) { $e_uri = pht('Invalid'); $errors[] = pht('Mailing list URI must point to a valid web page.'); } } if (!$errors) { try { $list->save(); return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI()); } catch (AphrontDuplicateKeyQueryException $ex) { $e_email = pht('Duplicate'); $errors[] = pht('Another mailing list already uses that address.'); } } } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($list->getID()) { $form->setAction($this->getApplicationURI('/edit/' . $list->getID() . '/')); } else { $form->setAction($this->getApplicationURI('/edit/')); } $form->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Email'))->setName('email')->setValue($list->getEmail())->setCaption(pht('Email will be delivered to this address.'))->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setError($e_name)->setCaption(pht('Human-readable display and autocomplete name.'))->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('URI'))->setName('uri')->setError($e_uri)->setCaption(pht('Optional link to mailing list archives or info.'))->setValue($list->getURI()))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save'))->addCancelButton($this->getApplicationURI())); if ($list->getID()) { $crumbs->addTextCrumb(pht('Edit Mailing List')); } else { $crumbs->addTextCrumb(pht('Create Mailing List')); } $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setFormErrors($errors)->setForm($form); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $page_title)); }