public function updatePage(Page $page)
 {
     $result = $this->pageDao->findByIdAndPosition($page->getId(), $page->getPosition());
     ResultHelper::whenEmpty($result, AppLabelUtil::$ERROR_PAGE_NOT_FOUND, HttpStatusCode::badRequest());
     $page->setPosition($result->getPosition());
     $this->pageDao->update($page);
 }
Example #2
0
 /**
  * Check if a page has any answers associated with it for a specific application
  * @param Page $page
  * @param Application $application
  * @return boolean
  */
 public function hasApplicationAnswers(Page $page, Application $application)
 {
     $query = $this->_em->createQuery('SELECT COUNT(answer.id) as ancnt FROM Jazzee\\Entity\\Answer answer JOIN answer.applicant applicant WHERE answer.page = :pageId AND applicant.application = :applicationId');
     $query->setParameter('pageId', $page->getId());
     $query->setParameter('applicationId', $application->getId());
     $result = $query->getResult();
     return $result[0]['ancnt'] > 0;
 }
/**
 * Populate options array with options recursivly
 *
 * @param Page $page
 * @param integer $value
 * @param User $user
 * @param Page $skip
 * @param array $options
 * @param string $indent
 * @return null
 */
function smarty_function_select_page_populate_options($page, $value, $user, $skip, &$options, $indent = '')
{
    if (instance_of($skip, 'Page') && $skip->getId() == $page->getId()) {
        return;
    }
    // if
    $attributes = $value == $page->getId() ? array('selected' => true) : null;
    $options[] = option_tag($indent . $page->getName(), $page->getId(), $attributes);
    $subpages = $page->getSubpages($user->getVisibility());
    if (is_foreachable($subpages)) {
        foreach ($subpages as $subpage) {
            smarty_function_select_page_populate_options($subpage, $value, $user, $skip, $options, $indent . '- ');
        }
        // foreach
    }
    // if
}
Example #4
0
 /**
  * @param page Page
  * @return PageDto
  */
 public function mapPageToDto(Page $page)
 {
     $pageDto = new PageDto();
     $pageDto->setId($page->getId());
     $pageDto->setTitle($page->getTitle());
     $pageDto->setName($page->getName());
     $pageDto->setDescription($page->getDescription());
     $pageDto->setPosition($page->getPosition());
     return $pageDto;
 }
Example #5
0
 /**
  * Find any unmatched score answers for a page
  * @param \Jazzee\Entity\Page $page
  * @return array
  */
 public function findUnMatchedScores(Page $page)
 {
     $query = 'SELECT a, e FROM Jazzee\\Entity\\Answer a ';
     $query .= 'LEFT JOIN a.elements e ';
     $query .= 'WHERE a.page = :pageId AND a.pageStatus IS NULL AND a.greScore IS NULL AND a.toeflScore IS NULL';
     $query = $this->_em->createQuery($query);
     $query->setParameter('pageId', $page->getId());
     $query->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, true);
     return $query->getArrayResult();
 }
 /**
  * Set parent page
  *
  * @param Page $page
  * @return null
  */
 function setPage($page)
 {
     $this->setPageId($page->getId());
     if ($this->isNew()) {
         $this->setName($page->old_name ? $page->old_name : $page->getName());
         $this->setBody($page->old_body ? $page->old_body : $page->getBody());
         $this->setVersion($page->getRevisionNum());
     }
     // if
 }
 function goto_tasks_page_for_user()
 {
     $user = Users::findById($this->request->getId('selected_user_id'));
     $page_title = $user->getName() . ' - Task List';
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     $query = "select id from healingcrystals_project_objects where type='Page' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='" . mysql_real_escape_string($page_title) . "'";
     $result = mysql_query($query, $link);
     if (mysql_num_rows($result)) {
         $info = mysql_fetch_assoc($result);
         $this->redirectToUrl(assemble_url('project_page', array('project_id' => TASK_LIST_PROJECT_ID, 'page_id' => $info['id'])));
     } else {
         $query = "select id from healingcrystals_project_objects where type='Category' and module='pages' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='General'";
         $page_category = mysql_query($query);
         $page_category_info = mysql_fetch_assoc($page_category);
         $page_data = array('type' => 'Page', 'module' => 'pages', 'visibility' => VISIBILITY_NORMAL, 'name' => $page_title, 'body' => 'Auto-generated Task List Page', 'integer_field_1' => '1');
         db_begin_work();
         $this->active_page = new Page();
         $this->active_page->setAttributes($page_data);
         $this->active_page->setProjectId(TASK_LIST_PROJECT_ID);
         $this->active_page->setCreatedBy($this->logged_user);
         $this->active_page->setState(STATE_VISIBLE);
         $this->active_page->setParentId($page_category_info['id']);
         $save = $this->active_page->save();
         if ($save && !is_error($save)) {
             //$subscribers = array($this->logged_user->getId());
             //if(!in_array($this->active_project->getLeaderId(), $subscribers)) {
             //	$subscribers[] = $this->active_project->getLeaderId();
             //}
             //Subscriptions::subscribeUsers($subscribers, $this->active_page);
             db_commit();
             $this->active_page->ready();
             $query = "select * from healingcrystals_project_users where user_id='" . $user->getId() . "' and project_id='" . TASK_LIST_PROJECT_ID . "'";
             $result = mysql_query($query, $link);
             if (!mysql_num_rows($result)) {
                 //mysql_query("insert into healingcrystals_project_users (user_id, project_id, role_id, permissions) values ('" . $user->getId() . "', '" . TASK_LIST_PROJECT_ID . "', '" . $user->getRoleId() . "', 'N;')");
                 mysql_query("insert into healingcrystals_project_users (user_id, project_id, role_id, permissions) values ('" . $user->getId() . "', '" . TASK_LIST_PROJECT_ID . "', '7', 'N;')");
             } elseif ($user->getRoleId() == '2') {
                 mysql_query("update healingcrystals_project_users set role_id='7' where user_id='" . $user->getId() . "' and project_id='" . TASK_LIST_PROJECT_ID . "'");
             }
             $this->redirectToUrl(assemble_url('project_page', array('project_id' => TASK_LIST_PROJECT_ID, 'page_id' => $this->active_page->getId())));
         } else {
             db_rollback();
             //$save .= 'rollback';
         }
     }
     mysql_close($link);
     $this->smarty->assign(array('user' => $user, 'project' => $this->active_project, 'errors' => $save, 'data' => $page_data));
 }
 /**
  * Return PlaceStorage model for given article
  *
  * @param Page $article article object
  * @return PlaceStorage model object
  */
 public static function newFromArticle(Page $article)
 {
     return self::newFromId($article->getId());
 }
 /**
  * Return subpages
  *
  * @param Page $page
  * @param integer $min_state
  * @param integer $min_visibility
  * @return array
  */
 function findSubpages($page, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     return Pages::find(array('conditions' => array('parent_id = ? AND type = ? AND state >= ? AND visibility >= ?', $page->getId(), 'Page', $min_state, $min_visibility, false), 'order' => 'ISNULL(position) ASC, position'));
 }
Example #10
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Page $value A Page object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Page $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 function move()
 {
     $new_parent_id = $this->request->post('new_parent_id');
     $new_parent_type = $this->request->post('new_parent_type');
     $new_parent_url = '';
     $move_mode = false;
     if (!empty($new_parent_id) && !empty($new_parent_type)) {
         $move_mode = true;
         $parent_obj = $sql_part = null;
         switch ($new_parent_type) {
             case 'milestone':
                 $parent_obj = new MileStone($new_parent_id);
                 break;
             case 'ticket':
                 $parent_obj = new Ticket($new_parent_id);
                 break;
             case 'page':
                 $parent_obj = new Page($new_parent_id);
                 break;
         }
         if ($parent_obj) {
             $body = $this->active_task->getBody();
             $doc = new DOMDocument();
             if ($doc->loadHTML($body)) {
                 $anc_tags = $doc->getElementsByTagName('a');
                 $new_parent_url = '';
                 foreach ($anc_tags as $anc) {
                     if ($anc->nodeValue == 'View Task in Full') {
                         $href = $anc->getAttribute('href');
                         $fragment = substr($href, strpos($href, '#'));
                         $anc->setAttribute('href', $parent_obj->getViewUrl() . $fragment);
                         break;
                     }
                 }
                 if (!empty($fragment)) {
                     $body_tag = $doc->getElementsByTagName('body');
                     $body = $doc->saveXML($body_tag->item(0)->firstChild);
                     $comment_id = str_replace('#comment', '', $fragment);
                 }
             }
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             $query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t  set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tbody = '" . mysql_real_escape_string($body) . "' \n\t\t\t\t\t\t  where\tid='" . $this->active_task->getId() . "'";
             mysql_query($query, $link);
             if (!empty($comment_id)) {
                 $comment_query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t  set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tposition=null\n\t\t\t\t\t\t  where\tid='" . $comment_id . "'";
                 mysql_query($comment_query, $link);
             }
             mysql_close($link);
             $new_parent_url = $parent_obj->getViewUrl() . '#task' . $this->active_task->getId();
             $cache_id = TABLE_PREFIX . 'project_objects_id_' . $this->active_task->getId();
             $cache_obj = cache_get($cache_id);
             if ($cache_obj) {
                 cache_remove($cache_id);
             }
         }
     } else {
         $listing = array();
         switch ($this->active_task_parent->getType()) {
             case 'Milestone':
                 //$listing = Milestones::findByProject($this->active_project, $this->logged_user);
                 $listing = Milestones::findActiveByProject_custom($this->active_project);
                 break;
             case 'Ticket':
                 $listing = Tickets::findOpenByProjectByNameSort($this->active_project, STATE_VISIBLE, $this->logged_user->getVisibility());
                 break;
             case 'Page':
                 $categories = Categories::findByModuleSection($this->active_project, 'pages', 'pages');
                 $listing = Pages::findByCategories($categories, STATE_VISIBLE, $this->logged_user->getVisibility());
                 /*foreach($categories as $category){
                 			$listing = array_merge($listing, Pages::findByCategory($category, STATE_VISIBLE, $this->logged_user->getVisibility()));
                 		}*/
                 break;
         }
         $this->smarty->assign(array('teams' => Projects::findNamesByUser($this->logged_user), 'listing' => $listing, 'task_parent_id' => $this->active_task_parent->getId()));
     }
     $this->smarty->assign('new_parent_url', $new_parent_url);
     $this->smarty->assign('move_mode', $move_mode);
 }
 /**
  * Deletes the form definition associated with the given wiki page
  * from the main cache.
  *
  * Hooks: ArticlePurge, ArticleSave
  *
  * @param Page $wikipage
  * @return bool
  */
 public static function purgeCache(Page $wikipage)
 {
     if (!$wikipage->getTitle()->inNamespace(SF_NS_FORM)) {
         return true;
     }
     $cache = self::getFormCache();
     $cacheKeyForList = self::getCacheKey($wikipage->getId());
     // get references to stored datasets
     $listOfFormKeys = $cache->get($cacheKeyForList);
     if (!is_array($listOfFormKeys)) {
         return true;
     }
     // delete stored datasets
     foreach ($listOfFormKeys as $key) {
         $cache->delete($key);
         wfDebug("Deleted cached form definition {$key}.\n");
     }
     // delete references to datasets
     $cache->delete($cacheKeyForList);
     wfDebug("Deleted cached form definition references {$cacheKeyForList}.\n");
     return true;
 }
Example #13
0
 public function displayPage(Page $page)
 {
     $pageIds = $this->getPageIds();
     return in_array($page->getId(), $pageIds);
 }
 function getPageId(&$incoming_mail, &$project, &$user)
 {
     $page_id = '';
     list($user_name, ) = explode('-', $incoming_mail->getSubject());
     $user_name = trim($user_name);
     $name_parts = explode(' ', $user_name);
     list($first_name, $last_name) = $name_parts;
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     $query = "select id from healingcrystals_users where first_name='" . mysql_real_escape_string($first_name) . "' " . (!empty($last_name) ? " and last_name='" . mysql_real_escape_string($last_name) . "' " : "");
     $result = mysql_query($query, $link);
     if (mysql_num_rows($result)) {
         $info = mysql_fetch_assoc($result);
         $user_id = $info['id'];
     } elseif (strpos($incoming_mail->getSubject(), '}') !== false) {
         $user_id = substr($incoming_mail->getSubject(), strrpos($incoming_mail->getSubject(), '{') + 1, -1);
     }
     if (!empty($user_id)) {
         $task_meant_for_user = Users::findById($user_id);
         $page_title = $task_meant_for_user->getName() . ' - Task List';
         //echo $page_title . '<br/>';
         $query2 = "select id from healingcrystals_project_objects where type='Page' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='" . mysql_real_escape_string($page_title) . "'";
         //echo $query2 . '<br/>';
         $result2 = mysql_query($query2, $link);
         if (mysql_num_rows($result2)) {
             $info2 = mysql_fetch_assoc($result2);
             $page_id = $info2['id'];
         } else {
             $query3 = "select id from healingcrystals_project_objects where type='Category' and module='pages' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='General'";
             //echo $query3 . '<br/>';
             $page_category = mysql_query($query3, $link);
             $page_category_info = mysql_fetch_assoc($page_category);
             $category_id = $page_category_info['id'];
             //echo $category_id . '<br/>';
             $page_data = array('type' => 'Page', 'module' => 'pages', 'visibility' => VISIBILITY_NORMAL, 'name' => $page_title, 'body' => 'Auto-generated Task List Page', 'integer_field_1' => '1');
             //print_r($page_data);
             //db_begin_work();
             $page = new Page();
             $page->setAttributes($page_data);
             $page->setProjectId(TASK_LIST_PROJECT_ID);
             $page->setCreatedBy($user);
             $page->setState(STATE_VISIBLE);
             $page->setParentId($category_id);
             $page->save();
             $page->ready();
             $page_id = $page->getId();
         }
         $query = "select * from healingcrystals_project_users where user_id='" . $task_meant_for_user->getId() . "' and project_id='" . TASK_LIST_PROJECT_ID . "'";
         $result = mysql_query($query, $link);
         if (!mysql_num_rows($result)) {
             //mysql_query("insert into healingcrystals_project_users (user_id, project_id, role_id, permissions) values ('" . $user->getId() . "', '" . TASK_LIST_PROJECT_ID . "', '" . $user->getRoleId() . "', 'N;')");
             mysql_query("insert into healingcrystals_project_users (user_id, project_id, role_id, permissions) values ('" . $task_meant_for_user->getId() . "', '" . TASK_LIST_PROJECT_ID . "', '7', 'N;')");
         } elseif ($user->getRoleId() == '2') {
             mysql_query("update healingcrystals_project_users set role_id='7' where user_id='" . $task_meant_for_user->getId() . "' and project_id='" . TASK_LIST_PROJECT_ID . "'");
         }
     }
     mysql_close($link);
     return $page_id;
 }
Example #15
0
 function getTaskPageIdForUser($user_id)
 {
     $page_id = '';
     $user = new User($user_id);
     $name = $user->getName();
     list($first_name, $last_name) = explode(' ', $name);
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME, $link);
     $page_title = $name . ' - Task List';
     $query2 = "select id from healingcrystals_project_objects where type='Page' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='" . mysql_real_escape_string($page_title) . "'";
     $result2 = mysql_query($query2, $link);
     if (mysql_num_rows($result2)) {
         $info2 = mysql_fetch_assoc($result2);
         $page_id = $info2['id'];
     } else {
         $query3 = "select id from healingcrystals_project_objects where type='Category' and module='pages' and project_id='" . TASK_LIST_PROJECT_ID . "' and name='General'";
         $page_category = mysql_query($query3, $link);
         $page_category_info = mysql_fetch_assoc($page_category);
         $category_id = $page_category_info['id'];
         $page_data = array('type' => 'Page', 'module' => 'pages', 'visibility' => VISIBILITY_NORMAL, 'name' => $page_title, 'body' => 'Auto-generated Task List Page', 'integer_field_1' => '1');
         $page = new Page();
         $page->setAttributes($page_data);
         $page->setProjectId(TASK_LIST_PROJECT_ID);
         $page->setCreatedBy($user);
         $page->setState(STATE_VISIBLE);
         $page->setParentId($category_id);
         $page->save();
         $page->ready();
         $page_id = $page->getId();
         $query = "select * from healingcrystals_project_users where user_id='" . $user_id . "' and project_id='" . TASK_LIST_PROJECT_ID . "'";
         $result = mysql_query($query, $link);
         if (!mysql_num_rows($result)) {
             mysql_query("insert into healingcrystals_project_users (user_id, project_id, role_id, permissions) values ('" . $user_id . "', '" . TASK_LIST_PROJECT_ID . "', '7', 'N;')");
         } elseif ($user->getRoleId() == '2') {
             mysql_query("update healingcrystals_project_users set role_id='7' where user_id='" . $user_id . "' and project_id='" . TASK_LIST_PROJECT_ID . "'");
         }
     }
     //mysql_close($link);
     return $page_id;
 }
Example #16
0
 /**
  * Exclude object from result
  *
  * @param   Page $page Object to remove from the list of results
  *
  * @return PageQuery The current query, for fluid interface
  */
 public function prune($page = null)
 {
     if ($page) {
         $this->addUsingAlias(PagePeer::ID, $page->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #17
0
 function lookup($id)
 {
     return $id && is_numeric($id) && ($p = new Page($id)) && $p->getId() == $id ? $p : null;
 }
Example #18
0
 public static function navigationItemForPage(Page $oPage, $oParent = null)
 {
     $sIdentifier = "{$oPage->getId()}";
     if (!isset(self::$NAVIGATION_ITEMS[$sIdentifier])) {
         self::$NAVIGATION_ITEMS[$sIdentifier] = new PageNavigationItem($oPage, $oParent);
     }
     return self::$NAVIGATION_ITEMS[$sIdentifier];
 }
 function convertToPage(&$logged_user, &$error)
 {
     db_begin_work();
     $page = new Page();
     $page->setProjectId($this->getProjectId());
     $page->setName($this->getName());
     $body = $this->getBody();
     if (empty($body)) {
         $body = 'page Content missing';
     }
     $page->setBody($body);
     $page->setState($this->getState());
     $page->setVisibility($this->getVisibility());
     $page->setPriority($this->getPriority());
     $page->setCommentsCount($this->getCommentsCount());
     $page->setIsLocked($this->getIsLocked());
     $page->setCreatedById($logged_user->getId());
     $page->setCreatedByName($logged_user->getName());
     $page->setCreatedByEmail($logged_user->getEmail());
     $save = $page->save();
     if ($save && !is_error($save)) {
         db_commit();
         $page->ready();
         $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
         mysql_select_db(DB_NAME);
         $query = "update healingcrystals_project_objects set parent_id='" . $page->getId() . "', parent_type='Page' where parent_id='" . $this->getId() . "' and project_id='" . $this->getProjectId() . "' and type in ('Comment', 'Task')";
         mysql_query($query);
         $query = "update healingcrystals_project_objects set parent_id=null, parent_type=null where parent_id='" . $this->getId() . "' and project_id='" . $this->getProjectId() . "' and type not in ('Comment', 'Task')";
         mysql_query($query);
         $query = "select * from healingcrystals_assignments where object_id='" . $this->getId() . "'";
         $result = mysql_query($query);
         while ($entry = mysql_fetch_assoc($result)) {
             $query = "insert into healingcrystals_assignments (user_id, object_id, is_owner) values ('" . $entry['user_id'] . "', '" . $page->getId() . "', '" . $entry['is_owner'] . "')";
             mysql_query($query);
         }
         $query = "select * from healingcrystals_project_object_categories where object_id='" . $this->getId() . "'";
         $result = mysql_query($query);
         while ($entry = mysql_fetch_assoc($result)) {
             $query = "insert ignore into healingcrystals_project_object_categories (object_id, category_id) values ('" . $page->getId() . "', '" . $entry['category_id'] . "')";
             mysql_query($query);
         }
         mysql_close($link);
         $this->moveToTrash();
         return $page->getId();
     } else {
         db_rollback();
         $error = $save;
         return '';
     }
 }
 /**
  * Return last page version
  *
  * @param Page $page
  * @return PageVersion
  */
 function findLatestByPage($page)
 {
     return PageVersions::find(array('conditions' => array('page_id = ?', $page->getId()), 'order' => 'version DESC', 'limit' => 1, 'offset' => 0, 'one' => true));
 }
Example #21
0
 public function add()
 {
     if (Page::already($_POST['baseUrl'], $_POST['uri'], $_POST['language'])) {
         throw new Exception('PAGE ALREADY EXISTS', 409);
     }
     $page = new Page();
     $page->setBaseUrl($_POST['baseUrl']);
     $page->setUri($_POST['uri']);
     $page->setLanguage($_POST['language']);
     if (array_key_exists('content', $_POST) && !empty($_POST['content'])) {
         $page->setContent($_POST['content']);
     }
     $page->setModele($_POST['modele']);
     $page->setTitle($_POST['title']);
     if (array_key_exists('languageParentId', $_POST)) {
         $page->setLanguageParentId($_POST['languageParentId']);
     }
     if (array_key_exists('ajax', $_POST)) {
         $page->setAjax($_POST['ajax']);
     }
     if (array_key_exists('published', $_POST)) {
         $page->setPublished($_POST['published']);
     }
     if (array_key_exists('metas', $_POST)) {
         $page->setMetas($_POST['metas']);
     }
     if (array_key_exists('css', $_POST)) {
         $page->setCss($_POST['css']);
     }
     if (array_key_exists('js', $_POST)) {
         $page->setJs($_POST['js']);
     }
     if (array_key_exists('action', $_POST)) {
         $page->setAction($_POST['action']);
     }
     if (array_key_exists('method', $_POST)) {
         $page->setMethod($_POST['method']);
     }
     if (array_key_exists('priority', $_POST)) {
         $page->setPriority($_POST['priority']);
     }
     if (array_key_exists('datas', $_POST)) {
         $page->setDatas($_POST['datas']);
     }
     if (!array_key_exists('blockIds', $_POST)) {
         $blkIds = array();
         foreach ($_POST['blockIds'] as $blk) {
             if (array_key_exists('id', $blk) && MongoId::isValid($blk['id'])) {
                 $blkIds[] = $blk['id'];
             }
         }
         $this->page->setBlockIds($blkIds);
     }
     $page->save();
     return array('pageId' => $page->getId());
 }
Example #22
0
 /**
  * Add a required page
  * @param Page $page
  */
 public function addRequiredPage(Page $page)
 {
     if (!$page->isGlobal()) {
         throw new \Jazzee\Exception("{$page->getTitle()} (#{$page->getId()}) is not a global page and cannot be a required page for a cycle");
     }
     $this->requiredPages[] = $page;
 }
Example #23
0
 /**
  * Return instance of WikiaPoll for given article from Poll namespace
  */
 public static function newFromArticle(Page $article)
 {
     $id = $article->getId();
     return self::newFromId($id);
 }
 /**
  * SyncRepositoryTask::execute()
  *
  * @param array $arguments
  * @param array $options
  * @return
  */
 protected function execute($arguments = array(), $options = array())
 {
     // ログファイルの設定
     $file_logger = new sfFileLogger($this->dispatcher, array('file' => $this->configuration->getRootDir() . '/log/' . $this->getName() . '.log'));
     $this->dispatcher->connect('application.log', array($file_logger, 'listenToLogEvent'));
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     // 更新フラグのあるリポジトリの最初の1件を取得する。
     $repository = RepositoryTable::getInstance()->findOneByForceUpdate(1);
     if (!$repository) {
         return false;
     }
     // 更新フラグを消しておく。
     $repository->setForceUpdate(0);
     $repository->save();
     // リポジトリを同期する。
     $this->log(sprintf('リポジトリ %s の同期を開始します', $repository->getRepositoryName()));
     // リポジトリキャッシュルートディレクトリ
     $cache_root = sfConfig::get('sf_root_dir') . '/../data/repos/';
     $dir_root = $cache_root . $repository->getCacheKey();
     $do_clone = false;
     if ($repository->getForceClone()) {
         // 一旦このディレクトリ配下をすべて削除する
         sfToolkit::clearDirectory($dir_root_repo);
         // 強制clone
         $do_clone = true;
     } else {
         if (!is_dir($dir_root)) {
             // ディレクトリがない。
             mkdir($dir_root, 0777, true);
             // このディレクトリ配下にcloneを取得する。
             $do_clone = true;
         } else {
             // リポジトリは取得済か?
             $dir_root_repo = $dir_root . DIRECTORY_SEPARATOR . $repository->getRepositoryName();
             try {
                 $git = new myVersionControl_Git($dir_root_repo);
                 $git->setGitCommandPath('git');
                 // pullする。
                 $this->log('リポジトリをpullしています');
                 $pullMessage = $git->getCommand('pull')->execute();
                 if (preg_match('/up\\-to\\-date/i', $pullMessage)) {
                     $this->log('更新はありません');
                     return;
                 }
             } catch (Exception $e) {
                 // 一旦このディレクトリ配下をすべて削除する
                 sfToolkit::clearDirectory($dir_root_repo);
                 // cloneする
                 $do_clone = true;
             }
         }
     }
     if ($do_clone) {
         $this->log('リポジトリをcloneしています');
         $git = new myVersionControl_Git($dir_root);
         $git->setGitCommandPath('git');
         $git->createClone($repository->getRepository());
         // リポジトリ
         $dir_root_repo = $dir_root . DIRECTORY_SEPARATOR . $repository->getRepositoryName();
         try {
             $git = new myVersionControl_Git($dir_root_repo);
             $git->setGitCommandPath('git');
         } catch (Exception $e) {
             // 一旦このディレクトリ配下をすべて削除する
             sfToolkit::clearDirectory($dir_root_repo);
             return;
         }
     }
     // このリポジトリの対象ファイルリストを取得する。
     $files = sfFinder::type('file')->prune('.git')->discard('.git')->relative()->in($search_dir = $dir_root . DIRECTORY_SEPARATOR . $repository->getRepositoryName() . $repository->getSubdirectory());
     $page_path_root = $repository->getBindPath();
     // ---------------------------------------------
     // ファイル別に処理
     $new_commit_found = false;
     foreach ($files as $file) {
         $this->log(sprintf('ファイル:%s', $file));
         $info = pathinfo($file);
         $file_path = $search_dir . DIRECTORY_SEPARATOR . $file;
         // ファイルの更新タイムスタンプが新しいものだけ処理する
         if (filemtime($file_path) < time() - 86400) {
             $this->log('更新なし');
             continue;
         }
         //  このファイルが対象かどうかチェックする。
         if (!PageTable::needProcess($file)) {
             $this->log('ページ取り込み対象外');
             // 画像データなら、パブリックディレクトリにコピーする。
             if (preg_match('/^(png|jpg|gif)$/', $info['extension'])) {
                 $target_path = $repository->getImagePublicPath($file);
                 $target_dir = dirname($target_path);
                 if (!is_dir($target_dir)) {
                     mkdir($target_dir, 0777, true);
                 }
                 $this->log('ファイルをパブリックディレクトリにコピーします。');
                 copy($file_path, $target_path);
                 chmod($target_path, 0666);
             }
             continue;
         }
         //  各ページに対応するURLパスを求める。
         if ('.' !== $info['dirname']) {
             $page_path = strtolower($page_path_root . '/' . $info['dirname'] . '/' . $info['filename']);
         } else {
             $page_path = strtolower($page_path_root . '/' . $info['filename']);
         }
         // ページに対応するレコードを取得する。
         $page = Doctrine_Core::getTable('Page')->findOneByPath($page_path);
         if (!$page) {
             $page = new Page();
             $page->setPath($page_path);
             $page->setRepository($repository);
         }
         echo $file;
         // ページごとにコミット履歴を取得する。
         $commits = $git->getCommits('master', $file_path);
         foreach ($commits as $commit) {
             // 既存ページの場合はコミットがすでに取り込み済かチェックする。
             $commit_record = null;
             if (!$page->isNew()) {
                 $commit_record = Doctrine_Core::getTable('Commit')->findOneByCommitKeyAndPageId($commit->__toString(), $page->getId());
             }
             if (!$commit_record) {
                 // コミットを登録する。
                 $new_commit_found = true;
                 $this->log(sprintf('コミット %s を取得しています', $commit));
                 $commit_record = new Commit();
                 $commit_record->setAuthorHandle($commit->getAuthorHandle());
                 $commit_record->setAuthorEmail($commit->getAuthorEmail());
                 $commit_record->setCommitterHandle($commit->getCommitterHandle());
                 $commit_record->setCommitterEmail($commit->getCommitterEmail());
                 $commit_record->setCommittedAt(date('Y/m/d H:i:s', $commit->getCommittedAt()));
                 $commit_record->setCommitKey($commit);
                 $commit_record->setPage($page);
                 $commit_record->save();
                 $commit_record->free();
                 unset($commit_record);
             }
         }
         //  新規のコミットが無い場合は、処理をスキップする。
         if (!$new_commit_found) {
             continue;
         }
         $new_commit_found = true;
         $page->setContentType($type = PageTable::checkType($file));
         $content = file_get_contents($file_path);
         if ('UTF-8' !== ($encoding = mb_detect_encoding($content))) {
             $content = mb_convert_encoding($content, 'UTF-8', $encoding);
         }
         $page->setContentRaw($content);
         // ページのレンダリングモードに合わせてレンダリングする。
         $page->setContentRendered($rendered = PageTable::renderContent($content, $type));
         // DOMパース用に、特殊文字を置換する。
         $html = mb_convert_encoding($rendered, 'HTML-ENTITIES', 'ASCII, JIS, UTF-8, EUC-JP, SJIS');
         // レンダリング結果をパースする。
         $dom = new DomDocument();
         $dom->loadHTML($html);
         $xpath = new DOMXPath($dom);
         // タイトルを探す。
         $domElements = $xpath->query('//title | //h1');
         if (count($domElements)) {
             $page->setTitle($domElements->item(0)->nodeValue);
         }
         // 見出しをパースする
         $domElements = $xpath->query('//h1 | //h2 | //h3');
         $indexes = array();
         $now_h1 = array();
         $now_h2 = array();
         foreach ($domElements as $domElement) {
             switch ($domElement->nodeName) {
                 case 'h1':
                     $indexes[] = array('type' => 'h1', 'text' => $domElement->nodeValue, 'id' => $domElement->getAttribute('id'), 'children' => array());
                     $now_h1 =& $indexes[count($indexes) - 1]['children'];
                     break;
                 case 'h2':
                     $now_h1[] = array('type' => 'h2', 'text' => $domElement->nodeValue, 'id' => $domElement->getAttribute('id'), 'children' => array());
                     $now_h2 =& $now_h1[count($now_h1) - 1]['children'];
                     break;
                 case 'h3':
                     $now_h2[] = array('type' => 'h3', 'text' => $domElement->nodeValue, 'id' => $domElement->getAttribute('id'), 'children' => array());
                     break;
                 default:
                     break;
             }
         }
         $page->setIndexJson(json_encode($indexes));
         // 保存する。
         $page->save();
         $page->free();
         unset($page);
     }
     // 新しいコミットがあった場合、キャッシュを削除する。
     if ($new_commit_found) {
         $frontend_cache_dir = sfConfig::get('sf_cache_dir') . '/frontend/prod/template';
         $cache = new sfFileCache(array('cache_dir' => $frontend_cache_dir));
         $cache->clean();
     }
     $this->log(sprintf('リポジトリ %s の同期が完了しました', $repository->getRepositoryName()));
 }
 /**
  * Update users params array for a user on edit
  * @param array $p user params
  * @param Page $article the article just edited
  * @param string $summary edit summary
  * @return bool anything changed
  */
 public static function updateUserParams(array &$p, Page $article, $summary)
 {
     global $wgFlaggedRevsAutoconfirm, $wgFlaggedRevsAutopromote;
     # Update any special counters for non-null revisions
     $changed = false;
     if ($article->getTitle()->isContentPage()) {
         $pages = $p['uniqueContentPages'];
         // page IDs
         # Don't let this get bloated for no reason
         $maxUniquePages = 50;
         // some flexibility
         if (is_array($wgFlaggedRevsAutoconfirm) && $wgFlaggedRevsAutoconfirm['uniqueContentPages'] > $maxUniquePages) {
             $maxUniquePages = $wgFlaggedRevsAutoconfirm['uniqueContentPages'];
         }
         if (is_array($wgFlaggedRevsAutopromote) && $wgFlaggedRevsAutopromote['uniqueContentPages'] > $maxUniquePages) {
             $maxUniquePages = $wgFlaggedRevsAutopromote['uniqueContentPages'];
         }
         if (count($pages) < $maxUniquePages && !in_array($article->getId(), $pages)) {
             $pages[] = $article->getId();
             $p['uniqueContentPages'] = $pages;
         }
         $p['totalContentEdits'] += 1;
         $changed = true;
     }
     // Record non-automatic summary tally
     if (!preg_match('/^\\/\\*.*\\*\\/$/', $summary)) {
         $p['editComments'] += 1;
         $changed = true;
     }
     return $changed;
 }
 /**
  * Filter the query by a related Page object
  *
  * @param   Page|PropelObjectCollection $page The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 ContentObjectQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterByPage($page, $comparison = null)
 {
     if ($page instanceof Page) {
         return $this->addUsingAlias(ContentObjectPeer::PAGE_ID, $page->getId(), $comparison);
     } elseif ($page instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(ContentObjectPeer::PAGE_ID, $page->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByPage() only accepts arguments of type Page or PropelCollection');
     }
 }
Example #27
0
 /**
  * Declares an association between this object and a Page object.
  *
  * @param                  Page $v
  * @return Right The current object (for fluent API support)
  * @throws PropelException
  */
 public function setPage(Page $v = null)
 {
     if ($v === null) {
         $this->setPageId(NULL);
     } else {
         $this->setPageId($v->getId());
     }
     $this->aPage = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Page object, it will not be re-added.
     if ($v !== null) {
         $v->addRight($this);
     }
     return $this;
 }
 public static function overrideRedirect(Title $title, WebRequest $request, &$ignoreRedirect, &$target, Page &$article)
 {
     global $wgMemc, $wgParserCacheExpireTime;
     $fa = FlaggableWikiPage::getTitleInstance($title);
     if (!$fa->isReviewable()) {
         return true;
         // nothing to do
     }
     # Viewing an old reviewed version...
     if ($request->getVal('stableid')) {
         $ignoreRedirect = true;
         // don't redirect (same as ?oldid=x)
         return true;
     }
     $srev = $fa->getStableRev();
     $view = FlaggablePageView::singleton();
     # Check if we are viewing an unsynced stable version...
     if ($srev && $view->showingStable() && $srev->getRevId() != $article->getLatest()) {
         # Check the stable redirect properties from the cache...
         $key = wfMemcKey('flaggedrevs', 'overrideRedirect', $article->getId());
         $tuple = FlaggedRevs::getMemcValue($wgMemc->get($key), $article);
         if (is_array($tuple)) {
             // cache hit
             list($ignoreRedirect, $target) = $tuple;
         } else {
             // cache miss; fetch the stable rev text...
             $text = $srev->getRevText();
             $redirect = $fa->getRedirectURL(Title::newFromRedirectRecurse($text));
             if ($redirect) {
                 $target = $redirect;
                 // use stable redirect
             } else {
                 $ignoreRedirect = true;
                 // make MW skip redirection
             }
             $data = FlaggedRevs::makeMemcObj(array($ignoreRedirect, $target));
             $wgMemc->set($key, $data, $wgParserCacheExpireTime);
             // cache results
         }
         $clearEnvironment = (bool) $target;
         # Check if the we are viewing a draft or synced stable version...
     } else {
         # In both cases, we can just let MW use followRedirect()
         # on the draft as normal, avoiding any page text hits.
         $clearEnvironment = $article->isRedirect();
     }
     # Environment will change in MediaWiki::initializeArticle
     if ($clearEnvironment) {
         $view->clear();
     }
     return true;
 }