/**
  * Remove this page from archive
  *
  * @param void
  * @return null
  */
 function unarchive()
 {
     if ($this->active_page->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->active_page->canEdit($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     if ($this->request->isSubmitted()) {
         $this->active_page->setIsArchived(false);
         $save = $this->active_page->save();
         if ($save && !is_error($save)) {
             if ($this->request->isApiCall()) {
                 $this->serveData($this->active_page, 'page');
             } else {
                 flash_success('Page ":name" has been archived', array('name' => $this->active_page->getName()));
             }
             // if
         } else {
             if ($this->request->isApiCall()) {
                 $this->serveData($save);
             } else {
                 flash_error('Failed to archive ":name" page', array('name' => $this->active_page->getName()));
             }
             // if
         }
         // if
         $this->redirectToUrl($this->active_page->getViewUrl());
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
 }
Example #2
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPageRelatedByParentId !== null) {
             if ($this->aPageRelatedByParentId->isModified() || $this->aPageRelatedByParentId->isNew()) {
                 $affectedRows += $this->aPageRelatedByParentId->save($con);
             }
             $this->setPageRelatedByParentId($this->aPageRelatedByParentId);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = PagePeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = PagePeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += PagePeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collPagesRelatedByParentId !== null) {
             foreach ($this->collPagesRelatedByParentId as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #3
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPage !== null) {
             if ($this->aPage->isModified() || $this->aPage->isNew()) {
                 $affectedRows += $this->aPage->save($con);
             }
             $this->setPage($this->aPage);
         }
         if ($this->aUserRelatedByCreatedBy !== null) {
             if ($this->aUserRelatedByCreatedBy->isModified() || $this->aUserRelatedByCreatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByCreatedBy->save($con);
             }
             $this->setUserRelatedByCreatedBy($this->aUserRelatedByCreatedBy);
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if ($this->aUserRelatedByUpdatedBy->isModified() || $this->aUserRelatedByUpdatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByUpdatedBy->save($con);
             }
             $this->setUserRelatedByUpdatedBy($this->aUserRelatedByUpdatedBy);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #4
0
 function executeSave()
 {
     $request = fvRequest::getInstance();
     if (!($Page = PageManager::getInstance()->getByPk($request->getRequestParameter('id')))) {
         $Page = new Page();
     }
     $p = $request->getRequestParameter('p');
     $meta = $request->getRequestParameter('meta');
     if ($Page->isNew()) {
         $defaultPage = PageManager::getInstance()->getByPageName('default');
         if (is_object($defaultPage = $defaultPage[0])) {
             if (!$p['page_title']) {
                 $p['page_title'] = $defaultPage->page_title;
             }
             if (!$p['page_description']) {
                 $p['page_description'] = $defaultPage->page_description;
             }
             if (!$p['page_keywords']) {
                 $p['page_keywords'] = $defaultPage->page_keywords;
             }
             if (!$p['page_content']) {
                 $p['page_content'] = $defaultPage->page_content;
             }
         }
     }
     $Page->addField("oldImage", 'string', $Page->image);
     $Page->updateFromRequest($p);
     $Page->getMeta()->updateFromRequest($meta);
     if ($Page->setMeta($Page->getMeta()) && $Page->save()) {
         fvResponce::getInstance()->setHeader('Id', $Page->getPk());
         $this->setFlash("Данные успешно сохранены", self::$FLASH_SUCCESS);
         fvResponce::getInstance()->setHeader('redirect', fvSite::$fvConfig->get('dir_web_root') . $request->getRequestParameter('module') . "/?id=" . $Page->getPk());
     } else {
         fvResponce::getInstance()->setHeader('X-JSON', json_encode($Page->getValidationResult()));
         $this->setFlash("Ошибка при сохранении данных проверте правильность введенных данных", self::$FLASH_ERROR);
     }
     if (fvRequest::getInstance()->isXmlHttpRequest()) {
         return self::$FV_AJAX_CALL;
     } else {
         return self::$FV_OK;
     }
 }
 /**
  * Render Page
  * 
  * @param void
  * @return null
  */
 function view()
 {
     if ($this->active_page->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND, null, true, $this->request->isApiCall());
     }
     // if
     if (!$this->active_page->canView($this->logged_user)) {
         $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
     }
     // if
     $this->addBreadcrumb($this->active_page->getName());
     $parent = $this->active_page->getParent();
     if (instance_of($parent, 'Page')) {
         $page_back_url = mobile_access_module_get_view_url($parent);
     } else {
         if (instance_of($parent, 'Category')) {
             $page_back_url = assemble_url('mobile_access_view_pages', array('project_id' => $this->active_project->getId(), 'category_id' => $parent->getId()));
         }
     }
     // if
     $this->smarty->assign(array('page_back_url' => $page_back_url));
 }
Example #6
0
 /**
  * Delete the given Field from the given Page
  *
  * Should delete entries from $field->table that belong to $page->id.
  * Possible template method.
  *
  * @param Page $page 
  * @param Field $field Field object
  * @return bool True on success, false on DB delete failure.
  *
  */
 public function ___deletePageField(Page $page, Field $field)
 {
     if (!$field->id) {
         throw new WireException("Unable to delete from '{$field->table}' for field that doesn't exist in fields table");
     }
     // no need to delete on a new Page because it's not in the table yet
     if ($page->isNew()) {
         return true;
     }
     // clear the value from the page
     // $page->set($field->name, $this->getBlankValue($page, $field));
     unset($page->{$field->name});
     // Delete all instances of it from the field table
     $sql = "DELETE FROM `{$field->table}` WHERE pages_id={$page->id}";
     return $this->fuel('db')->query($sql);
 }
Example #7
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPageRelatedByCanonicalId !== null) {
             if ($this->aPageRelatedByCanonicalId->isModified() || $this->aPageRelatedByCanonicalId->isNew()) {
                 $affectedRows += $this->aPageRelatedByCanonicalId->save($con);
             }
             $this->setPageRelatedByCanonicalId($this->aPageRelatedByCanonicalId);
         }
         if ($this->aUserRelatedByCreatedBy !== null) {
             if ($this->aUserRelatedByCreatedBy->isModified() || $this->aUserRelatedByCreatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByCreatedBy->save($con);
             }
             $this->setUserRelatedByCreatedBy($this->aUserRelatedByCreatedBy);
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if ($this->aUserRelatedByUpdatedBy->isModified() || $this->aUserRelatedByUpdatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByUpdatedBy->save($con);
             }
             $this->setUserRelatedByUpdatedBy($this->aUserRelatedByUpdatedBy);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->pagesRelatedByIdScheduledForDeletion !== null) {
             if (!$this->pagesRelatedByIdScheduledForDeletion->isEmpty()) {
                 foreach ($this->pagesRelatedByIdScheduledForDeletion as $pageRelatedById) {
                     // need to save related object because we set the relation to null
                     $pageRelatedById->save($con);
                 }
                 $this->pagesRelatedByIdScheduledForDeletion = null;
             }
         }
         if ($this->collPagesRelatedById !== null) {
             foreach ($this->collPagesRelatedById as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->pagePropertysScheduledForDeletion !== null) {
             if (!$this->pagePropertysScheduledForDeletion->isEmpty()) {
                 PagePropertyQuery::create()->filterByPrimaryKeys($this->pagePropertysScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->pagePropertysScheduledForDeletion = null;
             }
         }
         if ($this->collPagePropertys !== null) {
             foreach ($this->collPagePropertys as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->pageStringsScheduledForDeletion !== null) {
             if (!$this->pageStringsScheduledForDeletion->isEmpty()) {
                 PageStringQuery::create()->filterByPrimaryKeys($this->pageStringsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->pageStringsScheduledForDeletion = null;
             }
         }
         if ($this->collPageStrings !== null) {
             foreach ($this->collPageStrings as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->contentObjectsScheduledForDeletion !== null) {
             if (!$this->contentObjectsScheduledForDeletion->isEmpty()) {
                 ContentObjectQuery::create()->filterByPrimaryKeys($this->contentObjectsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->contentObjectsScheduledForDeletion = null;
             }
         }
         if ($this->collContentObjects !== null) {
             foreach ($this->collContentObjects as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->rightsScheduledForDeletion !== null) {
             if (!$this->rightsScheduledForDeletion->isEmpty()) {
                 RightQuery::create()->filterByPrimaryKeys($this->rightsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->rightsScheduledForDeletion = null;
             }
         }
         if ($this->collRights !== null) {
             foreach ($this->collRights as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Delete the given Field from the given Page
  *
  * Should delete entries from $field->table that belong to $page->id.
  * Possible template method.
  *
  * @param Page $page 
  * @param Field $field Field object
  * @return bool True on success, false on DB delete failure.
  * @throws WireException
  *
  */
 public function ___deletePageField(Page $page, Field $field)
 {
     if (!$field->id) {
         throw new WireException("Unable to delete from '{$field->table}' for field that doesn't exist in fields table");
     }
     // no need to delete on a new Page because it's not in the table yet
     if ($page->isNew()) {
         return true;
     }
     // clear the value from the page
     // $page->set($field->name, $this->getBlankValue($page, $field));
     unset($page->{$field->name});
     // Delete all instances of it from the field table
     $database = $this->wire('database');
     $table = $database->escapeTable($field->table);
     $page_id = (int) $page->id;
     $query = $database->prepare("DELETE FROM `{$table}` WHERE pages_id=:page_id");
     $query->bindValue(":page_id", $page_id, PDO::PARAM_INT);
     $result = $query->execute();
     return $result;
 }
Example #9
0
 /**
  * Save just a field from the given page as used by Page::save($field)
  *
  * This function is public, but the preferred manner to call it is with $page->save($field)
  *
  * @param Page $page
  * @param string|Field $field Field object or name (string)
  * @param array|string $options Specify option 'quiet' => true, to bypass updating of modified_users_id and modified time. 
  * @return bool True on success
  * @throws WireException
  *
  */
 public function ___saveField(Page $page, $field, $options = array())
 {
     $reason = '';
     if (is_string($options)) {
         $options = Selectors::keyValueStringToArray($options);
     }
     if ($page->isNew()) {
         throw new WireException("Can't save field from a new page - please save the entire page first");
     }
     if (!$this->isSaveable($page, $reason, $field, $options)) {
         throw new WireException("Can't save field from page {$page->id}: {$page->path}: {$reason}");
     }
     if ($field && (is_string($field) || is_int($field))) {
         $field = $this->fuel('fields')->get($field);
     }
     if (!$field instanceof Field) {
         throw new WireException("Unknown field supplied to saveField for page {$page->id}");
     }
     if (!$page->fields->has($field)) {
         throw new WireException("Page {$page->id} does not have field {$field->name}");
     }
     $value = $page->get($field->name);
     if ($value instanceof Pagefiles || $value instanceof Pagefile) {
         $page->filesManager()->save();
     }
     $page->trackChange($field->name);
     $this->saveFieldReady($page, $field);
     if ($field->type->savePageField($page, $field)) {
         $page->untrackChange($field->name);
         if (empty($options['quiet'])) {
             $user = $this->wire('user');
             $userID = (int) ($user ? $user->id : $this->config->superUserPageID);
             $database = $this->wire('database');
             $query = $database->prepare("UPDATE pages SET modified_users_id=:userID, modified=NOW() WHERE id=:pageID");
             $query->bindValue(':userID', $userID, PDO::PARAM_INT);
             $query->bindValue(':pageID', $page->id, PDO::PARAM_INT);
             $this->executeQuery($query);
         }
         $return = true;
         $this->savedField($page, $field);
     } else {
         $return = false;
     }
     $this->debugLog('saveField', "{$page}:{$field}", $return);
     return $return;
 }
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPage !== null) {
             if ($this->aPage->isModified() || $this->aPage->isNew()) {
                 $affectedRows += $this->aPage->save($con);
             }
             $this->setPage($this->aPage);
         }
         if ($this->aLanguage !== null) {
             if ($this->aLanguage->isModified() || $this->aLanguage->isNew()) {
                 $affectedRows += $this->aLanguage->save($con);
             }
             $this->setLanguage($this->aLanguage);
         }
         if ($this->aUserRelatedByCreatedBy !== null) {
             if ($this->aUserRelatedByCreatedBy->isModified() || $this->aUserRelatedByCreatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByCreatedBy->save($con);
             }
             $this->setUserRelatedByCreatedBy($this->aUserRelatedByCreatedBy);
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if ($this->aUserRelatedByUpdatedBy->isModified() || $this->aUserRelatedByUpdatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByUpdatedBy->save($con);
             }
             $this->setUserRelatedByUpdatedBy($this->aUserRelatedByUpdatedBy);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->searchIndexWordsScheduledForDeletion !== null) {
             if (!$this->searchIndexWordsScheduledForDeletion->isEmpty()) {
                 SearchIndexWordQuery::create()->filterByPrimaryKeys($this->searchIndexWordsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->searchIndexWordsScheduledForDeletion = null;
             }
         }
         if ($this->collSearchIndexWords !== null) {
             foreach ($this->collSearchIndexWords as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Example #11
0
 /**
  * Save just a field from the given page as used by Page::save($field)
  *
  * This function is public, but the preferred manner to call it is with $page->save($field)
  *
  * @param Page $page
  * @param string|Field $fieldName
  * @return bool True on success
  *
  */
 public function ___saveField(Page $page, $field)
 {
     $reason = '';
     if ($page->isNew()) {
         throw new WireException("Can't save field from a new page - please save the entire page first");
     }
     if (!$this->isSaveable($page, $reason)) {
         throw new WireException("Can't save field from page {$page->id}: {$page->path}: {$reason}");
     }
     if ($field && (is_string($field) || is_int($field))) {
         $field = $this->fuel('fields')->get($field);
     }
     if (!$field instanceof Field) {
         throw new WireException("Unknown field supplied to saveField for page {$page->id}");
     }
     if (!$page->fields->has($field)) {
         throw new WireException("Page {$page->id} does not have field {$field->name}");
     }
     $value = $page->get($field->name);
     if ($value instanceof Pagefiles || $value instanceof Pagefile) {
         $page->filesManager()->save();
     }
     $page->trackChange($field->name);
     if ($field->type->savePageField($page, $field)) {
         $page->untrackChange($field->name);
         $user = $this->fuel('user');
         $userID = (int) ($user ? $user->id : $this->config->superUserPageID);
         $this->db->query("UPDATE pages SET modified_users_id={$userID}, modified=NOW() WHERE id=" . (int) $page->id);
         $return = true;
     } else {
         $return = false;
     }
     $this->debugLog('saveField', "{$page}:{$field}", $return);
     return $return;
 }
 /**
  * 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()));
 }
Example #13
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPage !== null) {
             if ($this->aPage->isModified() || $this->aPage->isNew()) {
                 $affectedRows += $this->aPage->save($con);
             }
             $this->setPage($this->aPage);
         }
         if ($this->aUserRelatedByCreatedBy !== null) {
             if ($this->aUserRelatedByCreatedBy->isModified() || $this->aUserRelatedByCreatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByCreatedBy->save($con);
             }
             $this->setUserRelatedByCreatedBy($this->aUserRelatedByCreatedBy);
         }
         if ($this->aUserRelatedByUpdatedBy !== null) {
             if ($this->aUserRelatedByUpdatedBy->isModified() || $this->aUserRelatedByUpdatedBy->isNew()) {
                 $affectedRows += $this->aUserRelatedByUpdatedBy->save($con);
             }
             $this->setUserRelatedByUpdatedBy($this->aUserRelatedByUpdatedBy);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             // Rewind the condition_serialized LOB column, since PDO does not rewind after inserting value.
             if ($this->condition_serialized !== null && is_resource($this->condition_serialized)) {
                 rewind($this->condition_serialized);
             }
             $this->resetModified();
         }
         if ($this->languageObjectsScheduledForDeletion !== null) {
             if (!$this->languageObjectsScheduledForDeletion->isEmpty()) {
                 LanguageObjectQuery::create()->filterByPrimaryKeys($this->languageObjectsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->languageObjectsScheduledForDeletion = null;
             }
         }
         if ($this->collLanguageObjects !== null) {
             foreach ($this->collLanguageObjects as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->languageObjectHistorysScheduledForDeletion !== null) {
             if (!$this->languageObjectHistorysScheduledForDeletion->isEmpty()) {
                 LanguageObjectHistoryQuery::create()->filterByPrimaryKeys($this->languageObjectHistorysScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->languageObjectHistorysScheduledForDeletion = null;
             }
         }
         if ($this->collLanguageObjectHistorys !== null) {
             foreach ($this->collLanguageObjectHistorys as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Save a page object and it's fields to database. 
  *
  * If the page is new, it will be inserted. If existing, it will be updated. 
  *
  * This is the same as calling $page->save()
  *
  * If you want to just save a particular field in a Page, use $page->save($fieldName) instead. 
  *
  * @param Page $page
  * @return bool True on success
  *
  */
 public function ___save(Page $page)
 {
     $reason = '';
     $isNew = $page->isNew();
     if (!$this->isSaveable($page, $reason)) {
         throw new WireException("Can't save page {$page->id}: {$page->path}: {$reason}");
     }
     if ($page->parentPrevious) {
         if ($page->isTrash() && !$page->parentPrevious->isTrash()) {
             $this->trash($page, false);
         } else {
             if ($page->parentPrevious->isTrash() && !$page->parent->isTrash()) {
                 $this->restore($page, false);
             }
         }
     }
     $sql = "pages SET " . "parent_id=" . (int) $page->parent_id . ", " . "templates_id=" . (int) $page->template->id . ", " . "name='" . $this->db->escape_string($page->name) . "', " . "modified_users_id=" . (int) $this->fuel('user')->id . ", " . "status=" . (int) $page->status . ", " . "sort=" . (int) $page->sort . "," . "modified=NOW()";
     if ($isNew) {
         if ($page->id) {
             $sql .= ", id=" . (int) $page->id;
         }
         $result = $this->db->query("INSERT INTO {$sql}, created=NOW(), created_users_id=" . (int) $this->fuel('user')->id);
         if ($result) {
             $page->id = $this->db->insert_id;
         }
     } else {
         $result = $this->db->query("UPDATE {$sql} WHERE id=" . (int) $page->id);
     }
     if (!$result) {
         return false;
     }
     if (!$page->isChanged()) {
         return true;
     }
     // if page hasn't changed, don't continue further
     $page->filesManager->save();
     // save each individual Fieldtype data in the fields_* tables
     foreach ($page->fieldgroup as $field) {
         $field->type->savePageField($page, $field);
     }
     $this->getFuel('pagesRoles')->savePageRoles($page);
     $this->sortfields->save($page);
     // $page->removeStatus(Page::statusUnpublished);
     $page->resetTrackChanges();
     if ($isNew) {
         $page->setIsNew(false);
     }
     if ($page->templatePrevious && $page->templatePrevious->id != $page->template->id) {
         // the template was changed, so we may have data in the DB that is no longer applicable
         // find unused data and delete it
         foreach ($page->templatePrevious->fieldgroup as $field) {
             if ($page->template->fieldgroup->has($field)) {
                 continue;
             }
             $field->type->deletePageField($page, $field);
             if ($this->config->debug) {
                 $this->message("Deleted field '{$field}' on page {$page->url}");
             }
         }
     }
     // $page->getCacheFile()->remove();
     $this->uncacheAll();
     // lastly determine whether the pages_parents table needs to be updated for the find() cache
     // and call upon $this->saveParents where appropriate.
     if ($isNew && $page->parent_id) {
         $page = $page->parent;
     }
     // new page, lets focus on it's parent
     if ($page->numChildren || $isNew) {
         // check if entries aren't already present perhaps due to outside manipulation or an older version
         $result = $this->db->query("SELECT COUNT(*) FROM pages_parents WHERE parents_id={$page->id}");
         list($n) = $result->fetch_array();
         $result->free();
         // if entries aren't present, if the parent has changed, or if it's been forced in the API, proceed
         if ($n == 0 || $page->parentPrevious || $page->forceSaveParents === true) {
             $this->saveParents($page->id, $page->numChildren + ($isNew ? 1 : 0));
         }
     }
     return $result;
 }