public function processRequest() { $request = $this->getRequest(); $query = $request->getStr('q'); $repo_id = $request->getInt('repo'); $since = $request->getInt('since'); $limit = $request->getInt('limit'); $now = time(); $data = array(); // Dummy instances used for getting connections, table names, etc. $pr_commit = new PhabricatorRepositoryCommit(); $pr_commit_data = new PhabricatorRepositoryCommitData(); $conn = $pr_commit->establishConnection('r'); $rows = queryfx_all($conn, 'SELECT rc.phid as commitPHID, rc.authorPHID, rcd.authorName, SUBSTRING(rcd.commitMessage, 1, 100) AS shortMessage, rc.commitIdentifier, rc.epoch FROM %T rc INNER JOIN %T rcd ON rcd.commitID = rc.id WHERE repositoryID = %d AND rc.epoch >= %d AND ( rcd.commitMessage LIKE %~ OR rc.commitIdentifier LIKE %~ ) ORDER BY rc.epoch DESC LIMIT %d', $pr_commit->getTableName(), $pr_commit_data->getTableName(), $repo_id, $since, $query, $query, $limit); foreach ($rows as $row) { $full_commit_id = $row['commitIdentifier']; $short_commit_id = substr($full_commit_id, 0, 12); $first_line = $this->getFirstLine($row['shortMessage']); $data[] = array($full_commit_id, $short_commit_id, $row['authorName'], phutil_format_relative_time($now - $row['epoch']), $first_line); } return id(new AphrontAjaxResponse())->setContent($data); }
* * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ echo "Updating old commit authors...\n"; $table = new PhabricatorRepositoryCommit(); $conn = $table->establishConnection('w'); $data = new PhabricatorRepositoryCommitData(); $commits = queryfx_all($conn, 'SELECT c.id id, c.authorPHID authorPHID, d.commitDetails details FROM %T c JOIN %T d ON d.commitID = c.id WHERE c.authorPHID IS NULL', $table->getTableName(), $data->getTableName()); foreach ($commits as $commit) { $id = $commit['id']; $details = json_decode($commit['details'], true); $author_phid = idx($details, 'authorPHID'); if ($author_phid) { queryfx($conn, 'UPDATE %T SET authorPHID = %s WHERE id = %d', $table->getTableName(), $author_phid, $id); echo "#{$id}\n"; } } echo "Done.\n"; echo "Updating old commit mailKeys...\n"; $table = new PhabricatorRepositoryCommit(); $conn = $table->establishConnection('w'); $commits = queryfx_all($conn, 'SELECT id FROM %T WHERE mailKey = %s', $table->getTableName(), ''); foreach ($commits as $commit) {
<?php echo "Updating old commit authors...\n"; $table = new PhabricatorRepositoryCommit(); $table->openTransaction(); $conn = $table->establishConnection('w'); $data = new PhabricatorRepositoryCommitData(); $commits = queryfx_all($conn, 'SELECT c.id id, c.authorPHID authorPHID, d.commitDetails details FROM %T c JOIN %T d ON d.commitID = c.id WHERE c.authorPHID IS NULL FOR UPDATE', $table->getTableName(), $data->getTableName()); foreach ($commits as $commit) { $id = $commit['id']; $details = json_decode($commit['details'], true); $author_phid = idx($details, 'authorPHID'); if ($author_phid) { queryfx($conn, 'UPDATE %T SET authorPHID = %s WHERE id = %d', $table->getTableName(), $author_phid, $id); echo "#{$id}\n"; } } $table->saveTransaction(); echo "Done.\n"; echo "Updating old commit mailKeys...\n"; $table->openTransaction(); $commits = queryfx_all($conn, 'SELECT id FROM %T WHERE mailKey = %s FOR UPDATE', $table->getTableName(), ''); foreach ($commits as $commit) { $id = $commit['id']; queryfx($conn, 'UPDATE %T SET mailKey = %s WHERE id = %d', $table->getTableName(), Filesystem::readRandomCharacters(20), $id); echo "#{$id}\n"; } $table->saveTransaction();