diff --git a/scripts/__init_script__.php b/scripts/__init_script__.php index ba3c9562ae..fef1107998 100644 --- a/scripts/__init_script__.php +++ b/scripts/__init_script__.php @@ -1,35 +1,68 @@ array( 'javelin-util', 'javelin-install', 'javelin-event', 'javelin-stratcom', 'javelin-behavior', 'javelin-request', 'javelin-vector', 'javelin-dom', 'javelin-json', 'javelin-uri', ), 'typeahead.pkg.js' => array( 'javelin-typeahead', 'javelin-typeahead-normalizer', 'javelin-typeahead-source', 'javelin-typeahead-preloaded-source', 'javelin-typeahead-ondemand-source', 'javelin-tokenizer', 'javelin-behavior-aphront-basic-tokenizer', ), 'workflow.pkg.js' => array( 'javelin-mask', 'javelin-workflow', 'javelin-behavior-workflow', 'javelin-behavior-aphront-form-disable-on-submit', 'phabricator-keyboard-shortcut-manager', 'phabricator-keyboard-shortcut', 'javelin-behavior-phabricator-keyboard-shortcuts', ), 'core.pkg.css' => array( 'phabricator-core-css', 'phabricator-core-buttons-css', 'phabricator-standard-page-view', 'aphront-dialog-view-css', 'aphront-form-view-css', 'aphront-panel-view-css', 'aphront-side-nav-view-css', 'aphront-table-view-css', 'aphront-crumbs-view-css', 'aphront-tokenizer-control-css', 'aphront-typeahead-control-css', 'aphront-list-filter-view-css', 'phabricator-directory-css', 'phabricator-remarkup-css', 'syntax-highlighting-css', ), 'differential.pkg.css' => array( 'differential-core-view-css', 'differential-changeset-view-css', 'differential-revision-detail-css', 'differential-revision-history-css', 'differential-table-of-contents-css', 'differential-revision-comment-css', 'differential-revision-add-comment-css', 'differential-revision-comment-list-css', ), 'differential.pkg.js' => array( 'javelin-behavior-differential-feedback-preview', 'javelin-behavior-differential-edit-inline-comments', 'javelin-behavior-differential-populate', 'javelin-behavior-differential-show-more', 'javelin-behavior-differential-diff-radios', ), 'diffusion.pkg.css' => array( 'diffusion-commit-view-css', ), ); require_once dirname(__FILE__).'/__init_script__.php'; -require_once dirname(__FILE__).'/__init_env__.php'; if ($argc != 2) { $self = basename($argv[0]); echo "usage: {$self} \n"; exit(1); } phutil_require_module('phutil', 'filesystem'); phutil_require_module('phutil', 'filesystem/filefinder'); phutil_require_module('phutil', 'future/exec'); phutil_require_module('phutil', 'parser/docblock'); $root = Filesystem::resolvePath($argv[1]); echo "Finding static resources...\n"; $files = id(new FileFinder($root)) ->withType('f') ->withSuffix('js') ->withSuffix('css') ->withFollowSymlinks(true) ->setGenerateChecksums(true) ->find(); echo "Processing ".count($files)." files"; $resource_hash = PhabricatorEnv::getEnvConfig('celerity.resource-hash'); $file_map = array(); foreach ($files as $path => $hash) { echo "."; $name = '/'.Filesystem::readablePath($path, $root); $file_map[$name] = array( 'hash' => md5($hash.$name.$resource_hash), 'disk' => $path, ); } echo "\n"; $runtime_map = array(); $hash_map = array(); $parser = new PhutilDocblockParser(); foreach ($file_map as $path => $info) { $data = Filesystem::readFile($info['disk']); $matches = array(); $ok = preg_match('@/[*][*].*?[*]/@s', $data, $matches); if (!$ok) { throw new Exception( "File {$path} does not have a header doc comment. Encode dependency ". "data in a header docblock."); } list($description, $metadata) = $parser->parse($matches[0]); $provides = preg_split('/\s+/', trim(idx($metadata, 'provides'))); $requires = preg_split('/\s+/', trim(idx($metadata, 'requires'))); $provides = array_filter($provides); $requires = array_filter($requires); if (count($provides) > 1) { // NOTE: Documentation-only JS is permitted to @provide no targets. throw new Exception( "File {$path} must @provide at most one Celerity target."); } $provides = reset($provides); $type = 'js'; if (preg_match('/\.css$/', $path)) { $type = 'css'; } $uri = '/res/'.substr($info['hash'], 0, 8).$path; $hash_map[$provides] = $info['hash']; $runtime_map[$provides] = array( 'uri' => $uri, 'type' => $type, 'requires' => $requires, 'disk' => $path, ); } $package_map = array(); foreach ($package_spec as $name => $package) { $hashes = array(); $type = null; foreach ($package as $symbol) { if (empty($hash_map[$symbol])) { throw new Exception( "Package specification for '{$name}' includes '{$symbol}', but that ". "symbol is not defined anywhere."); } if ($type === null) { $type = $runtime_map[$symbol]['type']; } else { $ntype = $runtime_map[$symbol]['type']; if ($type !== $ntype) { throw new Exception( "Package specification for '{$name}' mixes resources of type ". "'{$type}' with resources of type '{$ntype}'. Each package may only ". "contain one type of resource."); } } $hashes[] = $symbol.':'.$hash_map[$symbol]; } $key = substr(md5(implode("\n", $hashes)), 0, 8); $package_map['packages'][$key] = array( 'name' => $name, 'symbols' => $package, 'uri' => '/res/pkg/'.$key.'/'.$name, 'type' => $type, ); foreach ($package as $symbol) { $package_map['reverse'][$symbol] = $key; } } ksort($runtime_map); $runtime_map = var_export($runtime_map, true); $runtime_map = preg_replace('/\s+$/m', '', $runtime_map); $runtime_map = preg_replace('/array \(/', 'array(', $runtime_map); ksort($package_map['packages']); ksort($package_map['reverse']); $package_map = var_export($package_map, true); $package_map = preg_replace('/\s+$/m', '', $package_map); $package_map = preg_replace('/array \(/', 'array(', $package_map); $resource_map = <<limit(8) as $file => $future) { $tree = XHPASTTree::newFromDataAndResolvedExecFuture( $data[$file], $future->resolve()); $root = $tree->getRootNode(); $functions = $root->selectDescendantsOfType('n_FUNCTION_DECLARATION'); foreach ($functions as $function) { $name = $function->getChildByIndex(2); print_symbol($file, 'function', $name); } $classes = $root->selectDescendantsOfType('n_CLASS_DECLARATION'); foreach ($classes as $class) { $class_name = $class->getChildByIndex(1); print_symbol($file, 'class', $class_name); } $interfaces = $root->selectDescendantsOfType('n_INTERFACE_DECLARATION'); foreach ($interfaces as $interface) { $interface_name = $interface->getChildByIndex(1); print_symbol($file, 'interface', $interface_name); } } function print_symbol($file, $type, $token) { $parts = array( $token->getConcreteString(), $type, 'php', $token->getLineNumber(), '/'.ltrim($file, './'), ); echo implode(' ', $parts)."\n"; } diff --git a/scripts/crossref/import_project_symbols.php b/scripts/crossref/import_project_symbols.php index 058e8d07f1..fde7fb9ebd 100755 --- a/scripts/crossref/import_project_symbols.php +++ b/scripts/crossref/import_project_symbols.php @@ -1,154 +1,153 @@ #!/usr/bin/env php loadOneWhere( 'name = %s', $project_name); if (!$project) { // TODO: Provide a less silly way to do this explicitly, or just do it right // here. echo "Project '{$project_name}' is unknown. Upload a diff to implicitly ". "create it.\n"; exit(1); } echo "Parsing input from stdin...\n"; $input = file_get_contents('php://stdin'); $input = trim($input); $input = explode("\n", $input); $map = array(); $symbols = array(); foreach ($input as $key => $line) { $line_no = $key + 1; $matches = null; $ok = preg_match('/^([^ ]+) ([^ ]+) ([^ ]+) (\d+) (.*)$/', $line, $matches); if (!$ok) { throw new Exception( "Line #{$line_no} of input is invalid. Expected five space-delimited ". "fields: symbol name, symbol type, symbol language, line number, path. ". "For example:\n\n". "idx function php 13 /path/to/some/file.php\n\n". "Actual line was:\n\n". "{$line}"); } list($all, $name, $type, $lang, $line_number, $path) = $matches; if (isset($map[$name][$type][$lang])) { $previous = $map[$name][$type][$lang] + 1; throw new Exception( "Line #{$line_no} of input is invalid. It specifies a duplicate symbol ". "(same name, language, and type) which has already been defined ". "elsewhere. You must preprocess the symbol list to remove duplicates ". "and choose exactly one master definition for each symbol. This symbol ". "was previously defined on line #{$previous}.\n\n". "Line #{$line_no}:\n". $line."\n\n". "Line #{$previous}:\n". $input[$previous - 1]); } else { $map[$name][$type][$lang] = $key; } if (strlen($name) > 128) { throw new Exception( "Symbol name '{$name}' defined on line #{$line_no} is too long, maximum ". "symbol name length is 128 characters."); } if (strlen($type) > 12) { throw new Exception( "Symbol type '{$type}' defined on line #{$line_no} is too long, maximum ". "symbol type length is 12 characters."); } if (strlen($lang) > 32) { throw new Exception( "Symbol language '{$lang}' defined on line #{$line_no} is too long, ". "maximum symbol language length is 32 characters."); } if (!strlen($path) || $path[0] != 0) { throw new Exception( "Path '{$path}' defined on line #{$line_no} is invalid. Paths should be ". "begin with '/' and specify a path from the root of the project, like ". "'/src/utils/utils.php'."); } $symbols[] = array( 'name' => $name, 'type' => $type, 'lang' => $lang, 'line' => $line_number, 'path' => $path, ); } echo "Looking up path IDs...\n"; $path_map = PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths( ipull($symbols, 'path')); $symbol = new PhabricatorRepositorySymbol(); $conn_w = $symbol->establishConnection('w'); echo "Preparing queries...\n"; $sql = array(); foreach ($symbols as $dict) { $sql[] = qsprintf( $conn_w, '(%d, %s, %s, %s, %d, %d)', $project->getID(), $dict['name'], $dict['type'], $dict['lang'], $dict['line'], $path_map[$dict['path']]); } echo "Purging old symbols...\n"; queryfx( $conn_w, 'DELETE FROM %T WHERE arcanistProjectID = %d', $symbol->getTableName(), $project->getID()); echo "Loading ".number_format(count($sql))." symbols...\n"; foreach (array_chunk($sql, 128) as $chunk) { queryfx( $conn_w, 'INSERT INTO %T (arcanistProjectID, symbolName, symbolType, symbolLanguage, lineNumber, pathID) VALUES %Q', $symbol->getTableName(), implode(', ', $chunk)); } echo "Done.\n"; diff --git a/scripts/daemon/phabricator_daemon_launcher.php b/scripts/daemon/phabricator_daemon_launcher.php index 08a04356d3..c1e1e36970 100755 --- a/scripts/daemon/phabricator_daemon_launcher.php +++ b/scripts/daemon/phabricator_daemon_launcher.php @@ -1,263 +1,262 @@ #!/usr/bin/env php executeListCommand(); exit($err); case 'status': $err = $control->executeStatusCommand(); exit($err); case 'stop': $pass_argv = array_slice($argv, 2); $err = $control->executeStopCommand($pass_argv); exit($err); case 'repository-launch-readonly': $need_launch = phd_load_tracked_repositories_of_type('git'); if (!$need_launch) { echo "There are no repositories with tracking enabled.\n"; } else { will_launch($control); foreach ($need_launch as $repository) { $name = $repository->getName(); $callsign = $repository->getCallsign(); $desc = "'{$name}' ({$callsign})"; $phid = $repository->getPHID(); echo "Launching 'git fetch' daemon on the {$desc} repository...\n"; $control->launchDaemon( 'PhabricatorRepositoryGitFetchDaemon', array( $phid, )); } } break; case 'repository-launch-master': $need_launch = phd_load_tracked_repositories(); if (!$need_launch) { echo "There are no repositories with tracking enabled.\n"; } else { will_launch($control); foreach ($need_launch as $repository) { $name = $repository->getName(); $callsign = $repository->getCallsign(); $desc = "'{$name}' ({$callsign})"; $phid = $repository->getPHID(); switch ($repository->getVersionControlSystem()) { case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: echo "Launching 'git fetch' daemon on the {$desc} repository...\n"; $control->launchDaemon( 'PhabricatorRepositoryGitFetchDaemon', array( $phid, )); echo "Launching discovery daemon on the {$desc} repository...\n"; $control->launchDaemon( 'PhabricatorRepositoryGitCommitDiscoveryDaemon', array( $phid, )); break; case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: echo "Launching discovery daemon on the {$desc} repository...\n"; $control->launchDaemon( 'PhabricatorRepositorySvnCommitDiscoveryDaemon', array( $phid, )); break; case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: echo "Launching 'hg pull' daemon on the {$desc} repository...\n"; $control->launchDaemon( 'PhabricatorRepositoryMercurialPullDaemon', array( $phid, )); echo "Launching discovery daemon on the {$desc} repository...\n"; $control->launchDaemon( 'PhabricatorRepositoryMercurialCommitDiscoveryDaemon', array( $phid, )); break; } } echo "Launching CommitTask daemon...\n"; $control->launchDaemon( 'PhabricatorRepositoryCommitTaskDaemon', array()); echo "Done.\n"; } break; case 'launch': case 'debug': $is_debug = ($argv[1] == 'debug'); $daemon = idx($argv, 2); if (!$daemon) { throw new Exception("Daemon name required!"); } $pass_argv = array_slice($argv, 3); $n = 1; if (!$is_debug) { if (is_numeric($daemon)) { $n = $daemon; if ($n < 1) { throw new Exception("Count must be at least 1!"); } $daemon = idx($argv, 3); if (!$daemon) { throw new Exception("Daemon name required!"); } $pass_argv = array_slice($argv, 4); } } $loader = new PhutilSymbolLoader(); $symbols = $loader ->setAncestorClass('PhutilDaemon') ->selectSymbolsWithoutLoading(); $symbols = ipull($symbols, 'name'); $match = array(); foreach ($symbols as $symbol) { if (stripos($symbol, $daemon) !== false) { if (strtolower($symbol) == strtolower($daemon)) { $match = array($symbol); break; } else { $match[] = $symbol; } } } if (count($match) == 0) { throw new Exception( "No daemons match! Use 'phd list' for a list of daemons."); } else if (count($match) > 1) { throw new Exception( "Which of these daemons did you mean?\n". " ".implode("\n ", $match)); } else { $daemon = reset($match); } $with_logs = true; if ($is_debug) { // In debug mode, we emit errors straight to stdout, so nothing useful // will show up in the logs. Don't echo the message about stuff showing // up in them, since it would be confusing. $with_logs = false; } will_launch($control, $with_logs); if ($is_debug) { echo "Launching {$daemon} in debug mode (nondaemonized)...\n"; } else { echo "Launching {$n} x {$daemon}"; } for ($ii = 0; $ii < $n; $ii++) { $control->launchDaemon($daemon, $pass_argv, $is_debug); if (!$is_debug) { echo "."; } } echo "\n"; echo "Done.\n"; break; case '--help': case 'help': default: $err = $control->executeHelpCommand(); exit($err); } function phd_load_tracked_repositories_of_type($type) { $repositories = phd_load_tracked_repositories(); foreach ($repositories as $key => $repository) { if ($repository->getVersionControlSystem() != $type) { unset($repositories[$key]); } } return $repositories; } function phd_load_tracked_repositories() { phutil_require_module( 'phabricator', 'applications/repository/storage/repository'); $repositories = id(new PhabricatorRepository())->loadAll(); foreach ($repositories as $key => $repository) { if (!$repository->isTracked()) { unset($repositories[$key]); } } return $repositories; } function will_launch($control, $with_logs = true) { echo "Staging launch...\n"; $control->pingConduit(); if ($with_logs) { $log_dir = $control->getControlDirectory('log').'/daemons.log'; echo "NOTE: Logs will appear in '{$log_dir}'.\n\n"; } } diff --git a/scripts/mail/mail_handler.php b/scripts/mail/mail_handler.php index e3225f3623..2b49c910bb 100755 --- a/scripts/mail/mail_handler.php +++ b/scripts/mail/mail_handler.php @@ -1,67 +1,66 @@ #!/usr/bin/php 1) { $_SERVER['PHABRICATOR_ENV'] = $argv[1]; } $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; require_once $root.'/externals/mimemailparser/MimeMailParser.class.php'; phutil_require_module( 'phabricator', 'applications/metamta/storage/receivedmail'); phutil_require_module( 'phabricator', 'applications/files/storage/file'); $parser = new MimeMailParser(); $parser->setText(file_get_contents('php://stdin')); $received = new PhabricatorMetaMTAReceivedMail(); $received->setHeaders($parser->getHeaders()); $received->setBodies(array( 'text' => $parser->getMessageBody('text'), 'html' => $parser->getMessageBody('html'), )); $attachments = array(); foreach ($parser->getAttachments() as $attachment) { if (preg_match('@text/(plain|html)@', $attachment->getContentType()) && $attachment->getContentDisposition() == 'inline') { // If this is an "inline" attachment with some sort of text content-type, // do not treat it as a file for attachment. MimeMailParser already picked // it up in the getMessageBody() call above. We still want to treat 'inline' // attachments with other content types (e.g., images) as attachments. continue; } $file = PhabricatorFile::newFromFileData( $attachment->getContent(), array( 'name' => $attachment->getFilename(), )); $attachments[] = $file->getPHID(); } $received->setAttachments($attachments); $received->save(); $received->processReceivedMail(); diff --git a/scripts/repository/rebuild_summaries.php b/scripts/repository/rebuild_summaries.php index 68fa69ecc3..a248d370ba 100755 --- a/scripts/repository/rebuild_summaries.php +++ b/scripts/repository/rebuild_summaries.php @@ -1,74 +1,73 @@ #!/usr/bin/env php establishConnection('w'); $sizes = queryfx_all( $conn_w, 'SELECT repositoryID, count(*) N FROM %T GROUP BY repositoryID', $commit->getTableName()); $sizes = ipull($sizes, 'N', 'repositoryID'); $maxes = queryfx_all( $conn_w, 'SELECT repositoryID, max(epoch) maxEpoch FROM %T GROUP BY repositoryID', $commit->getTableName()); $maxes = ipull($maxes, 'maxEpoch', 'repositoryID'); $repository_ids = array_keys($sizes + $maxes); echo "Updating ".count($repository_ids)." repositories"; foreach ($repository_ids as $repository_id) { $last_commit = queryfx_one( $conn_w, 'SELECT id FROM %T WHERE repositoryID = %d AND epoch = %d LIMIT 1', $commit->getTableName(), $repository_id, idx($maxes, $repository_id, 0)); if ($last_commit) { $last_commit = $last_commit['id']; } else { $last_commit = 0; } queryfx( $conn_w, 'INSERT INTO %T (repositoryID, lastCommitID, size, epoch) VALUES (%d, %d, %d, %d) ON DUPLICATE KEY UPDATE lastCommitID = VALUES(lastCommitID), size = VALUES(size), epoch = VALUES(epoch)', PhabricatorRepository::TABLE_SUMMARY, $repository_id, $last_commit, idx($sizes, $repository_id, 0), idx($maxes, $repository_id, 0)); echo "."; } echo "\ndone.\n"; diff --git a/scripts/repository/reparse.php b/scripts/repository/reparse.php index c9d435fff5..f6e0fff060 100755 --- a/scripts/repository/reparse.php +++ b/scripts/repository/reparse.php @@ -1,236 +1,235 @@ #!/usr/bin/env php loadOneWhere( 'callsign = %s OR phid = %s', $reparse_what, $reparse_what); if (!$repository) { throw new Exception("Unknown repository '{$reparse_what}'!"); } $commits = id(new PhabricatorRepositoryCommit())->loadAllWhere( 'repositoryID = %d', $repository->getID()); if (!$commits) { throw new Exception("No commits have been discovered in that repository!"); } $callsign = $repository->getCallsign(); } else { $matches = null; if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $reparse_what, $matches)) { throw new Exception("Can't parse commit identifier!"); } $callsign = $matches[1]; $commit_identifier = $matches[2]; $repository = id(new PhabricatorRepository())->loadOneWhere( 'callsign = %s', $callsign); if (!$repository) { throw new Exception("No repository with callsign '{$callsign}'!"); } $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 'repositoryID = %d AND commitIdentifier = %s', $repository->getID(), $commit_identifier); if (!$commit) { throw new Exception( "No matching commit '{$commit_identifier}' in repository '{$callsign}'. ". "(For git and mercurial repositories, you must specify the entire ". "commit hash.)"); } $commits = array($commit); } if ($is_all) { echo phutil_console_format( '**NOTE**: This script will queue tasks to reparse the data. Once the '. 'tasks have been queued, you need to run Taskmaster daemons to execute '. 'them.'); echo "\n\n"; echo "QUEUEING TASKS (".number_format(count($commits))." Commits):\n"; } $tasks = array(); foreach ($commits as $commit) { $classes = array(); switch ($repository->getVersionControlSystem()) { case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: if ($reparse_message) { $classes[] = 'PhabricatorRepositoryGitCommitMessageParserWorker'; } if ($reparse_change) { $classes[] = 'PhabricatorRepositoryGitCommitChangeParserWorker'; } break; case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: if ($reparse_message) { $classes[] = 'PhabricatorRepositoryMercurialCommitMessageParserWorker'; } if ($reparse_change) { $classes[] = 'PhabricatorRepositoryMercurialCommitChangeParserWorker'; } break; case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: if ($reparse_message) { $classes[] = 'PhabricatorRepositorySvnCommitMessageParserWorker'; } if ($reparse_change) { $classes[] = 'PhabricatorRepositorySvnCommitChangeParserWorker'; } break; } if ($reparse_herald) { $classes[] = 'PhabricatorRepositoryCommitHeraldWorker'; } $spec = array( 'commitID' => $commit->getID(), 'only' => true, ); if ($is_all) { foreach ($classes as $class) { $task = new PhabricatorWorkerTask(); $task->setTaskClass($class); $task->setData($spec); $task->save(); $commit_name = 'r'.$callsign.$commit->getCommitIdentifier(); echo " Queued '{$class}' for commit '{$commit_name}'.\n"; } } else { foreach ($classes as $class) { $worker = newv($class, array($spec)); echo "Running '{$class}'...\n"; $worker->doWork(); } } } echo "\nDone.\n"; function usage($message) { echo "Usage Error: {$message}"; echo "\n\n"; echo "Run 'reparse.php --help' for detailed help.\n"; exit(1); } function help() { $help = <<\n"; exit(1); } echo phutil_console_wrap( phutil_console_format( 'This script will test that you have configured valid credentials for '. 'access to a repository, so the Phabricator daemons can pull from it. '. 'You should run this as the **same user you will run the daemons as**, '. 'from the **same machine they will run from**. Doing this will help '. 'detect various problems with your configuration, such as SSH issues.')); list($whoami) = execx('whoami'); $whoami = trim($whoami); $ok = phutil_console_confirm("Do you want to continue as '{$whoami}'?"); if (!$ok) { die(1); } $callsign = $argv[1]; echo "Loading '{$callsign}' repository...\n"; $repository = id(new PhabricatorRepository())->loadOneWhere( 'callsign = %s', $argv[1]); if (!$repository) { throw new Exception("No such repository exists!"); } $vcs = $repository->getVersionControlSystem(); PhutilServiceProfiler::installEchoListener(); echo "Trying to connect to the remote...\n"; switch ($vcs) { case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: $err = $repository->passthruRemoteCommand( '--limit 1 log %s', $repository->getRemoteURI()); break; case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: // Do an ls-remote on a nonexistent ref, which we expect to just return // nothing. $err = $repository->passthruRemoteCommand( 'ls-remote %s %s', $repository->getRemoteURI(), 'just-testing'); break; case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: // TODO: 'hg id' doesn't support --insecure so we can't tell it not to // spew. If 'hg id' eventually supports --insecure, consider using it. echo "(It is safe to ignore any 'certificate with fingerprint ... not ". "verified' warnings, although you may want to configure Mercurial ". "to recognize the server's fingerprint/certificate.)\n"; $err = $repository->passthruRemoteCommand( 'id --rev tip %s', $repository->getRemoteURI()); break; default: throw new Exception("Unsupported repository type."); } if ($err) { echo phutil_console_format( "** FAIL ** Connection failed. The credentials for this ". "repository appear to be incorrectly configured.\n"); exit(1); } else { echo phutil_console_format( "** OKAY ** Connection successful. The credentials for ". "this repository appear to be correctly configured.\n"); } diff --git a/scripts/search/index_one_commit.php b/scripts/search/index_one_commit.php index b89faefe10..d75f8c3184 100755 --- a/scripts/search/index_one_commit.php +++ b/scripts/search/index_one_commit.php @@ -1,53 +1,52 @@ #!/usr/bin/env php \n"; die(1); } $commit = isset($argv[1]) ? $argv[1] : null; if (!$commit) { throw new Exception("Provide a commit to index!"); } $matches = null; if (!preg_match('/r([A-Z]+)([a-z0-9]+)/', $commit, $matches)) { throw new Exception("Can't parse commit identifier!"); } $repo = id(new PhabricatorRepository())->loadOneWhere( 'callsign = %s', $matches[1]); if (!$repo) { throw new Exception("Unknown repository!"); } $commit = id(new PhabricatorRepositoryCommit())->loadOneWhere( 'repositoryID = %d AND commitIdentifier = %s', $repo->getID(), $matches[2]); if (!$commit) { throw new Exception('Unknown commit.'); } PhabricatorSearchCommitIndexer::indexCommit($commit); echo "Done.\n"; diff --git a/scripts/search/reindex_all_users.php b/scripts/search/reindex_all_users.php index 3c9f576404..b829d5843a 100755 --- a/scripts/search/reindex_all_users.php +++ b/scripts/search/reindex_all_users.php @@ -1,32 +1,31 @@ #!/usr/bin/env php loadAll(); echo "Indexing ".count($users)." users"; foreach ($users as $user) { PhabricatorSearchUserIndexer::indexUser($user); echo '.'; } echo "\n"; echo "Done.\n"; diff --git a/scripts/search/reindex_everything.php b/scripts/search/reindex_everything.php index d0ee0079c6..0e4eea2c03 100755 --- a/scripts/search/reindex_everything.php +++ b/scripts/search/reindex_everything.php @@ -1,57 +1,56 @@ #!/usr/bin/env php loadAll(); $count = count($revs); echo "Reindexing {$count} revisions"; foreach ($revs as $rev) { PhabricatorSearchDifferentialIndexer::indexRevision($rev); echo '.'; } echo "\n"; echo "Loading commits...\n"; $commits = id(new PhabricatorRepositoryCommit())->loadAll(); $count = count($commits); echo "Reindexing {$count} commits"; foreach ($commits as $commit) { PhabricatorSearchCommitIndexer::indexCommit($commit); echo '.'; } echo "\n"; echo "Loading tasks...\n"; $tasks = id(new ManiphestTask())->loadAll(); $count = count($tasks); echo "Reindexing {$count} tasks"; foreach ($tasks as $task) { PhabricatorSearchManiphestIndexer::indexTask($task); echo '.'; } echo "\n"; echo "Done.\n"; diff --git a/scripts/search/reindex_maniphest.php b/scripts/search/reindex_maniphest.php index 45a99b4788..89235c6590 100755 --- a/scripts/search/reindex_maniphest.php +++ b/scripts/search/reindex_maniphest.php @@ -1,33 +1,32 @@ #!/usr/bin/env php loadAll(); echo "Updating relationships for ".count($tasks)." tasks"; foreach ($tasks as $task) { ManiphestTaskProject::updateTaskProjects($task); ManiphestTaskSubscriber::updateTaskSubscribers($task); echo '.'; } echo "\nDone.\n"; diff --git a/scripts/sql/upgrade_schema.php b/scripts/sql/upgrade_schema.php index 04bc25efab..673b0608d8 100755 --- a/scripts/sql/upgrade_schema.php +++ b/scripts/sql/upgrade_schema.php @@ -1,201 +1,200 @@ #!/usr/bin/env php null, // Upgrade from specific version 'u' => null, // Override MySQL User 'p' => null, // Override MySQL Pass ); foreach (array('h', 'f') as $key) { // By default, these keys are set to 'false' to indicate that the flag was // passed. if (array_key_exists($key, $options)) { $options[$key] = true; } } if (!empty($options['h']) || ($options['v'] && !is_numeric($options['v']))) { usage(); } if (empty($options['f'])) { echo phutil_console_wrap( "Before running this script, you should take down the Phabricator web ". "interface and stop any running Phabricator daemons."); if (!phutil_console_confirm('Are you ready to continue?')) { echo "Cancelled.\n"; exit(1); } } // Use always the version from the commandline if it is defined $next_version = isset($options['v']) ? (int)$options['v'] : null; $conf = DatabaseConfigurationProvider::getConfiguration(); if ($options['u']) { $conn_user = $options['u']; $conn_pass = $options['p']; } else { $conn_user = $conf->getUser(); $conn_pass = $conf->getPassword(); } $conn_host = $conf->getHost(); // Split out port information, since the command-line client requires a // separate flag for the port. $uri = new PhutilURI('mysql://'.$conn_host); if ($uri->getPort()) { $conn_port = $uri->getPort(); $conn_bare_hostname = $uri->getDomain(); } else { $conn_port = null; $conn_bare_hostname = $conn_host; } $conn = new AphrontMySQLDatabaseConnection( array( 'user' => $conn_user, 'pass' => $conn_pass, 'host' => $conn_host, 'database' => null, )); try { $create_sql = <<getMessage(). "\n\n"; exit(1); } function usage() { echo "usage: upgrade_schema.php [-v version] [-u user -p pass] [-f] [-h]". "\n\n". "Run 'upgrade_schema.php -u root -p hunter2' to override the configured ". "default user.\n". "Run 'upgrade_schema.php -v 12' to apply all patches starting from ". "version 12. It is very unlikely you need to do this.\n". "Use the -f flag to upgrade noninteractively, without prompting.\n". "Use the -h flag to show this help.\n"; exit(1); } diff --git a/scripts/user/account_admin.php b/scripts/user/account_admin.php index 7ceeff230b..cadab1db62 100755 --- a/scripts/user/account_admin.php +++ b/scripts/user/account_admin.php @@ -1,150 +1,149 @@ #!/usr/bin/env php loadOneWhere( 'username = %s', $username); if (!$user) { $original = new PhabricatorUser(); echo "There is no existing user account '{$username}'.\n"; $ok = phutil_console_confirm( "Do you want to create a new '{$username}' account?", $default_no = false); if (!$ok) { echo "Cancelled.\n"; exit(1); } $user = new PhabricatorUser(); $user->setUsername($username); } else { $original = clone $user; echo "There is an existing user account '{$username}'.\n"; $ok = phutil_console_confirm( "Do you want to edit the existing '{$username}' account?", $default_no = false); if (!$ok) { echo "Cancelled.\n"; exit(1); } } $user_realname = $user->getRealName(); if (strlen($user_realname)) { $realname_prompt = ' ['.$user_realname.']'; } else { $realname_prompt = ''; } $realname = nonempty( phutil_console_prompt("Enter user real name{$realname_prompt}:"), $user_realname); $user->setRealName($realname); $user_email = $user->getEmail(); if (strlen($user_email)) { $email_prompt = ' ['.$user_email.']'; } else { $email_prompt = ''; } do { $email = nonempty( phutil_console_prompt("Enter user email address{$email_prompt}:"), $user_email); $duplicate = id(new PhabricatorUser())->loadOneWhere( 'email = %s', $email); if ($duplicate && $duplicate->getID() != $user->getID()) { $duplicate_username = $duplicate->getUsername(); echo "ERROR: There is already a user with that email address ". "({$duplicate_username}). Each user must have a unique email ". "address.\n"; } else { break; } } while (true); $user->setEmail($email); $changed_pass = false; // This disables local echo, so the user's password is not shown as they type // it. phutil_passthru('stty -echo'); $password = phutil_console_prompt( "Enter a password for this user [blank to leave unchanged]:"); phutil_passthru('stty echo'); if (strlen($password)) { $changed_pass = $password; } $is_admin = $user->getIsAdmin(); $set_admin = phutil_console_confirm( 'Should this user be an administrator?', $default_no = !$is_admin); $user->setIsAdmin($set_admin); echo "\n\nACCOUNT SUMMARY\n\n"; $tpl = "%12s %-30s %-30s\n"; printf($tpl, null, 'OLD VALUE', 'NEW VALUE'); printf($tpl, 'Username', $original->getUsername(), $user->getUsername()); printf($tpl, 'Real Name', $original->getRealName(), $user->getRealName()); printf($tpl, 'Email', $original->getEmail(), $user->getEmail()); printf($tpl, 'Password', null, ($changed_pass !== false) ? 'Updated' : 'Unchanged'); printf( $tpl, 'Admin', $original->getIsAdmin() ? 'Y' : 'N', $user->getIsAdmin() ? 'Y' : 'N'); echo "\n"; if (!phutil_console_confirm("Save these changes?", $default_no = false)) { echo "Cancelled.\n"; exit(1); } $user->save(); if ($changed_pass !== false) { // This must happen after saving the user because we use their PHID as a // component of the password hash. $user->setPassword($changed_pass); $user->save(); } echo "Saved changes.\n"; diff --git a/src/infrastructure/daemon/base/PhabricatorDaemon.php b/src/infrastructure/daemon/base/PhabricatorDaemon.php index 0f6d56e14f..a53257bc6a 100644 --- a/src/infrastructure/daemon/base/PhabricatorDaemon.php +++ b/src/infrastructure/daemon/base/PhabricatorDaemon.php @@ -1,38 +1,35 @@ getPhabricatorTestCaseConfiguration() + array( self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK => true, ); } protected function willRunTests() { $root = dirname(phutil_get_library_root('phabricator')); - require_once $root.'/scripts/__init_env__.php'; + require_once $root.'/scripts/__init_script__.php'; $config = $this->getComputedConfiguration(); if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) { LiskDAO::beginIsolateAllLiskEffectsToCurrentProcess(); } } protected function didRunTests() { $config = $this->getComputedConfiguration(); if ($config[self::PHABRICATOR_TESTCONFIG_ISOLATE_LISK]) { LiskDAO::endIsolateAllLiskEffectsToCurrentProcess(); } } }