function commit_symbols($syms, $project, $no_purge) { echo "Looking up path IDs...\n"; $path_map = PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths(ipull($syms, 'path')); $symbol = new PhabricatorRepositorySymbol(); $conn_w = $symbol->establishConnection('w'); echo "Preparing queries...\n"; $sql = array(); foreach ($syms as $dict) { $sql[] = qsprintf($conn_w, '(%d, %s, %s, %s, %s, %d, %d)', $project->getID(), $dict['ctxt'], $dict['name'], $dict['type'], $dict['lang'], $dict['line'], $path_map[$dict['path']]); } if (!$no_purge) { echo "Purging old syms...\n"; queryfx($conn_w, 'DELETE FROM %T WHERE arcanistProjectID = %d', $symbol->getTableName(), $project->getID()); } echo "Loading " . number_format(count($sql)) . " syms...\n"; foreach (array_chunk($sql, 128) as $chunk) { queryfx($conn_w, 'INSERT INTO %T (arcanistProjectID, symbolContext, symbolName, symbolType, symbolLanguage, lineNumber, pathID) VALUES %Q', $symbol->getTableName(), implode(', ', $chunk)); } }
function commit_symbols(array $symbols, PhabricatorRepository $repository, $no_purge) { echo pht('Looking up path IDs...'), "\n"; $path_map = PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths(ipull($symbols, 'path')); $symbol = new PhabricatorRepositorySymbol(); $conn_w = $symbol->establishConnection('w'); echo pht('Preparing queries...'), "\n"; $sql = array(); foreach ($symbols as $dict) { $sql[] = qsprintf($conn_w, '(%s, %s, %s, %s, %s, %d, %d)', $repository->getPHID(), $dict['ctxt'], $dict['name'], $dict['type'], $dict['lang'], $dict['line'], $path_map[$dict['path']]); } if (!$no_purge) { echo pht('Purging old symbols...'), "\n"; queryfx($conn_w, 'DELETE FROM %T WHERE repositoryPHID = %s', $symbol->getTableName(), $repository->getPHID()); } echo pht('Loading %s symbols...', phutil_count($sql)), "\n"; foreach (array_chunk($sql, 128) as $chunk) { queryfx($conn_w, 'INSERT INTO %T (repositoryPHID, symbolContext, symbolName, symbolType, symbolLanguage, lineNumber, pathID) VALUES %Q', $symbol->getTableName(), implode(', ', $chunk)); } }
/** * @task exec */ public function execute() { if ($this->name && $this->namePrefix) { throw new Exception("You can not set both a name and a name prefix!"); } else { if (!$this->name && !$this->namePrefix) { throw new Exception("You must set a name or a name prefix!"); } } $symbol = new PhabricatorRepositorySymbol(); $conn_r = $symbol->establishConnection('r'); $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $symbol->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r)); $symbols = $symbol->loadAllFromArray($data); if ($symbols) { if ($this->needPaths) { $this->loadPaths($symbols); } if ($this->needArcanistProjects || $this->needRepositories) { $this->loadArcanistProjects($symbols); } if ($this->needRepositories) { $this->loadRepositories($symbols); } } return $symbols; }
$args = new PhutilArgumentParser($argv); $args->setSynopsis(<<<EOSYNOPSIS **clear_repository_symbols.php** [__options__] __repository__ Clear repository symbols. EOSYNOPSIS ); $args->parseStandardArguments(); $args->parse(array(array('name' => 'repository', 'wildcard' => true))); $identifiers = $args->getArg('repository'); if (count($identifiers) !== 1) { $args->printHelpAndExit(); } $identifier = head($identifiers); $repository = id(new PhabricatorRepositoryQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIdentifiers($identifiers)->executeOne(); if (!$repository) { echo tsprintf("%s\n", pht('Repository "%s" does not exist.', $identifier)); exit(1); } $input = file_get_contents('php://stdin'); $normalized = array(); foreach (explode("\n", trim($input)) as $path) { // Emulate the behavior of the symbol generation scripts. $normalized[] = '/' . ltrim($path, './'); } $paths = PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths($normalized); $symbol = new PhabricatorRepositorySymbol(); $conn_w = $symbol->establishConnection('w'); foreach (array_chunk(array_values($paths), 128) as $chunk) { queryfx($conn_w, 'DELETE FROM %T WHERE repositoryPHID = %s AND pathID IN (%Ld)', $symbol->getTableName(), $repository->getPHID(), $chunk); }
<?php $table = new PhabricatorRepositorySymbol(); $conn_w = $table->establishConnection('w'); $projects = queryfx_all($conn_w, 'SELECT * FROM %T', 'repository_arcanistproject'); foreach ($projects as $project) { $repo = id(new PhabricatorRepositoryQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIDs(array($project['repositoryID']))->executeOne(); if (!$repo) { continue; } echo pht("Migrating symbols for '%s' project...\n", $project['name']); queryfx($conn_w, 'UPDATE %T SET repositoryPHID = %s WHERE arcanistProjectID = %d', $table->getTableName(), $repo->getPHID(), $project['id']); }
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";
/** * @task exec */ public function execute() { if ($this->name && $this->namePrefix) { throw new Exception("You can not set both a name and a name prefix!"); } else { if (!$this->name && !$this->namePrefix) { throw new Exception("You must set a name or a name prefix!"); } } $symbol = new PhabricatorRepositorySymbol(); $conn_r = $symbol->establishConnection('r'); $where = array(); if ($this->name) { $where[] = qsprintf($conn_r, 'symbolName = %s', $this->name); } if ($this->namePrefix) { $where[] = qsprintf($conn_r, 'symbolName LIKE %>', $this->namePrefix); } if ($this->projectIDs) { $where[] = qsprintf($conn_r, 'arcanistProjectID IN (%Ld)', $this->projectIDs); } $where = 'WHERE (' . implode(') AND (', $where) . ')'; $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q', $symbol->getTableName(), $where); // Our ability to match up symbol types and languages probably isn't all // that great, so use them as hints for ranking rather than hard // requirements. TODO: Is this really the right choice? foreach ($data as $key => $row) { $score = 0; if ($this->language && $row['symbolLanguage'] == $this->language) { $score += 2; } if ($this->type && $row['symbolType'] == $this->type) { $score += 1; } $data[$key]['score'] = $score; $data[$key]['id'] = $key; } $data = isort($data, 'score'); $data = array_reverse($data); $data = array_slice($data, 0, $this->limit); $symbols = $symbol->loadAllFromArray($data); if ($symbols) { if ($this->needPaths) { $this->loadPaths($symbols); } if ($this->needArcanistProjects || $this->needRepositories) { $this->loadArcanistProjects($symbols); } if ($this->needRepositories) { $this->loadRepositories($symbols); } } return $symbols; }
#!/usr/bin/env php <?php $root = dirname(dirname(dirname(__FILE__))); require_once $root . '/scripts/__init_script__.php'; $project = id(new PhabricatorRepositoryArcanistProject())->loadOneWhere('name = %s', $argv[1]); if (!$project) { throw new Exception('No such arcanist project.'); } $input = file_get_contents('php://stdin'); $normalized = array(); foreach (explode("\n", trim($input)) as $path) { // emulate the behavior of the symbol generation scripts $normalized[] = '/' . ltrim($path, './'); } $paths = PhabricatorRepositoryCommitChangeParserWorker::lookupOrCreatePaths($normalized); $symbol = new PhabricatorRepositorySymbol(); $conn_w = $symbol->establishConnection('w'); foreach (array_chunk(array_values($paths), 128) as $chunk) { queryfx($conn_w, 'DELETE FROM %T WHERE arcanistProjectID = %d AND pathID IN (%Ld)', $symbol->getTableName(), $project->getID(), $chunk); }