/** * @param sfWebRequest $request * @return void */ public function execute($request) { $this->list = null; $this->userIsAuthenticated = $this->getUser()->isAuthenticated(); $this->currentBreadCrumbFile = null; $this->currentBreadCrumbBranch = null; $this->currentBreadCrumbRepository = null; $this->fileBreadCrumbList = array(); $this->branchBreadCrumbList = array(); $this->repositoryBreadCrumbList = array(); if ($fileId = $request->getParameter('file')) { $this->currentBreadCrumbFile = FileQuery::create()->filterById($fileId)->findOne(); $this->fileBreadCrumbList = FileQuery::create()->filterById($fileId, Criteria::NOT_EQUAL)->filterByBranchId($this->currentBreadCrumbFile->getBranchId())->filterByIsBinary(false)->orderByFilename()->find(); } $branchId = $request->getParameter('branch'); if (!$branchId) { $branchId = null != $this->currentBreadCrumbFile ? $this->currentBreadCrumbFile->getBranchId() : null; } if (null !== $branchId) { $this->currentBreadCrumbBranch = BranchQuery::create()->filterById($branchId)->findOne(); $this->branchBreadCrumbList = BranchQuery::create()->filterById($branchId, Criteria::NOT_EQUAL)->filterByRepositoryId($this->currentBreadCrumbBranch->getRepositoryId())->orderByName()->find(); } $repositoryId = $request->getParameter('repository'); if (!$repositoryId) { $repositoryId = null != $this->currentBreadCrumbBranch ? $this->currentBreadCrumbBranch->getRepositoryId() : null; } if (null !== $repositoryId) { $this->currentBreadCrumbRepository = RepositoryQuery::create()->filterById($repositoryId)->findOne(); $this->repositoryBreadCrumbList = RepositoryQuery::create()->filterById($repositoryId, Criteria::NOT_EQUAL)->orderByName()->find(); } }
/** * @param int $id * @param int $status * @param PropelPDO $con * @return string */ public function changeFileStatus($id, $status, PropelPDO $con) { $file = FileQuery::create()->filterById($id)->findOne(); $this->forward404Unless($file, 'File `%s` Not Found', $id); $oldStatus = $file->getStatus(); $file->changeStatus($status, $this->getUser()->getId(), $con); $this->dispatcher->notify(new sfEvent($this, 'notification.status', array('project-id' => $file->getBranch($con)->getRepositoryId(), 'type' => 'file', 'object' => $file, 'old' => $oldStatus))); }
/** * @static * @param int $userId * @param int $repositoryId * @param int $branchId * @param int $fileId * @param int $oldStatus * @param int $newStatus * @param string $message * @return int */ public static function saveAction($userId, $repositoryId, $branchId, $fileId, $oldStatus, $newStatus, $message = 'status was changed from <strong>%s</strong> to <strong>%s</strong>') { if ($oldStatus === $newStatus) { return 0; } $file = FileQuery::create()->filterById($fileId)->findOne(); if (!$file) { return false; } $statusAction = new StatusAction(); return $statusAction->setUserId($userId)->setRepositoryId($repositoryId)->setBranchId($branchId)->setFileId($fileId)->setOldStatus($oldStatus)->setNewStatus($newStatus)->setMessage(sprintf($message, BranchPeer::getLabelStatus($oldStatus), BranchPeer::getLabelStatus($newStatus), $file->getFilename(), $file->getBranch()->__toString()))->save(); }
/** * @return bool * @throws \Exception */ protected function initFile() { if (parent::initFile()) { return true; } $this->fp = @fopen($this->filename, 'rb'); if ($this->fp === FALSE) { throw new \Exception("Invalid {$this->filename} file!"); } $offset = unpack('Nlen', fread($this->fp, 4)); $this->offset = $offset['len'] - 1024; if ($this->offset < 4) { throw new \Exception("Invalid {$this->filename} file!"); } $this->end = $this->offset - 4; $this->index = fread($this->fp, $this->end); $this->rewind(); return true; }
/** * @static * @param GitCommand $gitCommand * @param Branch $branch * @param string $lastBranchSynchronizationCommit * @return int 0 if succeed */ public static function synchronize(GitCommand $gitCommand, Branch $branch, $lastBranchSynchronizationCommit = null) { $filesGit = $gitCommand->getDiffFilesFromBranch($branch->getRepository()->getGitDir(), $branch->getCommitReference(), $branch->getLastCommit()); if (count($filesGit) > sfConfig::get('app_max_number_of_files_to_review', 4096)) { return count($filesGit); } $filesModel = FileQuery::create()->filterByBranchId($branch->getId())->find(); if (count($filesModel) > 0) { $diffFilesFromLastSynch = $gitCommand->getDiffFilesFromBranch($branch->getRepository()->getGitDir(), !is_null($lastBranchSynchronizationCommit) ? $lastBranchSynchronizationCommit : $branch->getCommitReference(), $branch->getLastCommit(), false); } foreach ($filesModel as $fileModel) { /** @var $fileModel File */ if (!array_key_exists($fileModel->getFilename(), $filesGit)) { $fileModel->delete(); } else { $lastChangeCommit = $gitCommand->getLastModificationCommit($branch->getRepository()->getGitDir(), $branch->getName(), $fileModel->getFilename()); if (isset($diffFilesFromLastSynch[$fileModel->getFilename()])) { $fileModel->setReviewRequest(true)->setStatus(BranchPeer::A_TRAITER)->setCommitStatusChanged($lastChangeCommit); } else { $fileModel->setReviewRequest(false); } if ($filesGit[$fileModel->getFilename()]['is-binary']) { $fileModel->setIsBinary(true)->setNbAddedLines(0)->setNbDeletedLines(0); } else { $fileModel->setIsBinary(false)->setNbAddedLines($filesGit[$fileModel->getFilename()]['added-lines'])->setNbDeletedLines($filesGit[$fileModel->getFilename()]['deleted-lines']); } $fileModel->setState($filesGit[$fileModel->getFilename()]['state'])->setLastChangeCommit($lastChangeCommit)->setCommitInfos($gitCommand->getCommitInfos($branch->getRepository()->getGitDir(), $lastChangeCommit, "%ce %s"))->setCommitReference($branch->getCommitReference())->save(); } unset($filesGit[$fileModel->getFilename()]); } foreach ($filesGit as $fileGit) { $lastChangeCommit = $gitCommand->getLastModificationCommit($branch->getRepository()->getGitDir(), $branch->getName(), $fileGit['filename']); $file = new File(); if ($fileGit['is-binary']) { $file->setIsBinary(true)->setNbAddedLines(0)->setNbDeletedLines(0); } else { $file->setIsBinary(false)->setNbAddedLines($fileGit['added-lines'])->setNbDeletedLines($fileGit['deleted-lines']); } $file->setFilename($fileGit['filename'])->setStatus(BranchPeer::A_TRAITER)->setState($fileGit['state'])->setBranchId($branch->getId())->setLastChangeCommit($lastChangeCommit)->setCommitInfos($gitCommand->getCommitInfos($branch->getRepository()->getGitDir(), $lastChangeCommit, "%ce %s"))->setCommitReference($branch->getCommitReference())->setReviewRequest(true)->save(); } return 0; }
/** * @param sfWebRequest $request * @return application/json data */ public function execute($request) { if ($request->getMethod() == \sfWebRequest::GET) { $datas = array('commit' => $request->getParameter('commit'), 'file_id' => $request->getParameter('fileId'), 'position' => $request->getParameter('position'), 'line' => $request->getParameter('line'), 'user_id' => $this->getUser()->getId()); } else { if ($request->getMethod() == \sfWebRequest::POST) { // get the propel connection $con = Propel::getConnection(); $con->beginTransaction(); try { // get the comment arguments parameter $datas = $request->getParameter('comment'); $this->forward404Unless($datas, "Comment arguments not found"); $commit = $datas['commit']; $this->forward404Unless($commit, 'Commit Hash Not Found'); $fileId = $datas['file_id']; $this->forward404Unless($fileId, 'File Id Not Found'); $file = FileQuery::create()->filterById($fileId)->findOne(); $this->forward404Unless($file, 'File Not Found'); $position = $datas['position']; $this->forward404Unless($position, 'Position Line Number Not Found'); $line = $datas['line']; $this->forward404Unless($line, 'Line Number Not Found'); $value = $datas['value']; $this->forward404Unless($value, 'Comment Value Not Found'); // new comment object $lineComment = new Comment(); $lineComment->setUserId($this->getUser()->getId())->setCommit($commit)->setBranchId($file->getBranchId())->setFileId($fileId)->setPosition($position)->setLine($line)->setType(CommentPeer::TYPE_LINE)->setValue($value)->save($con); $lineComment->getBranch()->setReviewRequest(false)->save(); $datas = array_merge($datas, array('form_visible' => false)); $con->commit(); $this->dispatcher->notify(new sfEvent($this, 'notification.comment', array('project-id' => $lineComment->getBranch()->getRepositoryId(), 'type' => 'line', 'object' => $lineComment))); } catch (Exception $e) { $con->rollBack(); throw $e; } } } // returns a json object $this->getResponse()->setContentType('application/json'); return $this->renderText(json_encode(array('html' => $this->getComponent('default', 'commentLine', $datas)))); }
/** * @return bool * @throws \Exception */ protected function initFile() { if (parent::initFile()) { return true; } $this->fp = @fopen($this->filename, 'rb'); if ($this->fp === FALSE) { throw new \Exception("Invalid {$this->filename} file!"); } $offset = unpack('Vlen', fread($this->fp, 4)); $end = unpack('Vlen', fread($this->fp, 4)); $this->end = $end['len'] - $offset['len'] + 7; if ($offset['len'] < 4) { throw new \Exception("Invalid {$this->filename} file!"); } if ($this->end < 7) { throw new \Exception("Invalid {$this->filename} file!"); } fseek($this->fp, $offset['len']); $this->index = fread($this->fp, $this->end); return true; }
/** * @param sfWebRequest $request * @return void */ public function execute($request) { $this->branch = null; if ($request->hasParameter('name') && $request->hasParameter('repository')) { $repository = RepositoryQuery::create()->filterByName($request->getParameter('repository'))->findOne(); $this->forward404Unless($repository, "Repository not found"); $this->branch = BranchQuery::create()->filterByName($request->getParameter('name'))->filterByRepository($repository)->findOne(); // Dirty hack to make the breadcrumb work /!\ if ($this->branch) { $this->redirect('default/fileList?branch=' . $this->branch->getId()); } } elseif ($request->hasParameter('branch')) { $this->branch = BranchPeer::retrieveByPK($request->getParameter('branch')); } $this->forward404Unless($this->branch, "Branch not found"); $this->getResponse()->setTitle($this->branch->getName()); $this->repository = RepositoryPeer::retrieveByPK($this->branch->getRepositoryId()); $this->forward404Unless($this->repository, "Repository not found"); $files = FileQuery::create()->filterByBranchId($this->branch->getId())->find(); $this->files = array(); foreach ($files as $file) { $fileCommentsCount = CommentQuery::create()->filterByFileId($file->getId())->filterByType(CommentPeer::TYPE_FILE)->count(); $fileCommentsCountNotChecked = CommentQuery::create()->filterByFileId($file->getId())->filterByType(CommentPeer::TYPE_FILE)->filterByCheckUserId(null)->count(); $lineCommentsCount = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->filterByType(CommentPeer::TYPE_LINE)->count(); $lineCommentsCountNotChecked = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->filterByType(CommentPeer::TYPE_LINE)->filterByCheckUserId(null)->count(); $lastCommentId = 0; if ($fileCommentsCount || $lineCommentsCount) { $lastComment = CommentQuery::create()->filterByFileId($file->getId())->filterByCommit($file->getLastChangeCommit())->_or()->filterByType(CommentPeer::TYPE_FILE)->orderById(Criteria::DESC)->findOne(); if ($lastComment) { $lastCommentId = $lastComment->getId(); } } $this->files[] = array_merge($file->toArray(), array('NbFileComments' => $fileCommentsCount + $lineCommentsCount, 'NbFileCommentsNotChecked' => $fileCommentsCountNotChecked + $lineCommentsCountNotChecked, 'LastCommentId' => $lastCommentId)); } usort($this->files, array('self', 'sortPath')); $this->statusActions = StatusActionPeer::getStatusActionsForBoard(null, $this->repository->getId(), $this->branch->getId()); $this->commentBoards = CommentPeer::getCommentsForBoard(null, $this->repository->getId(), $this->branch->getId()); }
/** * @param sfWebRequest $request * @return void */ public function execute($request) { $this->file = FilePeer::retrieveByPK($request->getParameter('file')); $this->forward404Unless($this->file, "File not found"); $this->getResponse()->setTitle(basename($this->file->getFilename())); $this->previousFileId = FileQuery::create()->select('Id')->filterByBranchId($this->file->getBranchId())->filterByFilename($this->file->getFilename(), Criteria::LESS_THAN)->filterByIsBinary(false)->orderByFilename(Criteria::DESC)->findOne(); $this->nextFileId = FileQuery::create()->select('Id')->filterByBranchId($this->file->getBranchId())->filterByFilename($this->file->getFilename(), Criteria::GREATER_THAN)->filterByIsBinary(false)->orderByFilename(Criteria::ASC)->findOne(); $this->branch = BranchPeer::retrieveByPK($this->file->getBranchId()); $this->forward404Unless($this->branch, "Branch not found"); $this->repository = RepositoryPeer::retrieveByPK($this->branch->getRepositoryId()); $this->forward404Unless($this->repository, "Repository not found"); $options = array(); if ($request->getParameter('s', false)) { $options['ignore-all-space'] = true; } $this->fileContentLines = $this->gitCommand->getShowFileFromBranch($this->repository->getGitDir(), $this->branch->getCommitReference(), $this->file->getLastChangeCommit(), $this->file->getFilename(), $options); $fileLineCommentsModel = CommentQuery::create()->filterByFileId($this->file->getId())->filterByCommit($this->file->getLastChangeCommit())->filterByType(CommentPeer::TYPE_LINE)->find(); $this->userId = $this->getUser()->getId(); $this->fileLineComments = array(); foreach ($fileLineCommentsModel as $fileLineCommentModel) { $this->fileLineComments[$fileLineCommentModel->getPosition()][] = $fileLineCommentModel; } }
/** * Get the associated File object * * @param PropelPDO Optional Connection object. * @return File The associated File object. * @throws PropelException */ public function getFile(PropelPDO $con = null) { if ($this->aFile === null && $this->file_id !== null) { $this->aFile = FileQuery::create()->findPk($this->file_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aFile->addComments($this); */ } return $this->aFile; }
* qaulhub_file.php?id=123 */ // include needed configuration & libraries require_once '../qaulhub/config.php'; require_once '../qaulhub/helper_functions.php'; // check get variables if (isset($_GET['id'])) { $id = $_GET['id']; } else { $id = 0; } // pull messages from data base if ($id) { $files = FileQuery::create()->filterById(array('min' => $id))->orderById('asc')->limit(30)->find(); } else { $files = FileQuery::create()->orderById('desc')->limit(150)->find(); } // send json to client $first = true; echo "{\"files\":[\n"; foreach ($files as $file) { if ($first) { $first = false; } else { echo ",\n"; } echo "{"; echo '"id":' . $file->getId() . ','; echo '"hash":"' . $file->getHash() . '",'; echo '"suffix":"' . $file->getSuffix() . '",'; echo '"size":' . $file->getSize() . ',';
/** * Returns all files matching a given locale and a given domains. * * @param array $locales * @param array $domains * @return array */ public function findForLocalesAndDomains(array $locales, array $domains) { return FileQuery::create()->_if(count($locales) > 0)->filterByLocale($locales, \Criteria::IN)->_endif()->_if(count($domains) > 0)->filterByDomain($domains, \Criteria::IN)->_endif()->find($this->getConnection()); }
/** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this sfGuardUser is new, it will return * an empty collection; or if this sfGuardUser has previously * been saved, it will retrieve related Files from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in sfGuardUser. * * @param Criteria $criteria optional Criteria object to narrow the query * @param PropelPDO $con optional connection object * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN) * @return PropelCollection|array File[] List of File objects */ public function getFilesJoinBranch($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN) { $query = FileQuery::create(null, $criteria); $query->joinWith('Branch', $join_behavior); return $this->getFiles($query, $con); }
// loop through messages foreach ($data->files as $item) { // check if has been successfully downloaded if ($item->status >= 4) { // check if file already exists $file = FileQuery::create()->filterByHash($item->hash)->findOne(); if (!$file) { // put file information into data base $file = new File(); $file->setHash($item->hash); $file->setSuffix($item->suffix); $file->setDescription($item->description); $file->setSize($item->size); $file->setTime($item->time); $file->setStatus($item->status); $file->save(); // advertise this file via twitter // TODO: send images < 3MB directly to twitter $txt = $file->getDescription() . " " . twitter_file_link($file); twitter_send2twitter($txt); if (get_debug()) { echo "advertised file on twitter: {$txt}\n"; } } } else { if ($item->status == -2) { // delete file $file = FileQuery::create()->filterByHash($item->hash)->delete(); } } }
/** * Returns a new FileQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return FileQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof FileQuery) { return $criteria; } $query = new FileQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/* * qaul.net is free software * licensed under GPL (version 3) */ /** * this scripts redirects the browser from a short link with file id to the file download. * * invoke this script via web browser: * /f/file2db.php?id=123 */ // include needed configuration & libraries require_once '../../qaulhub/config.php'; // get id $id = $_GET['id']; // get file by id $q = new FileQuery(); $file = $q->findPK($id); if (!$file) { // file was not found echo "file not found ..."; exit; } header("Location: ../files/" . $file->getHash() . "." . $file->getSuffix()); exit; /* $path = get_qaul_setting('download_folder') .$file->getHash() ."." .$file->getSuffix(); if (file_exists($path) && is_readable($path)) { //header('Content-type: '.$mime); header('Content-length: '.filesize($path));
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(FilePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = FileQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); // symfony_behaviors behavior foreach (sfMixer::getCallables('BaseFile:delete:pre') as $callable) { if (call_user_func($callable, $this, $con)) { $con->commit(); return; } } if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); // symfony_behaviors behavior foreach (sfMixer::getCallables('BaseFile:delete:post') as $callable) { call_user_func($callable, $this, $con); } $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }