[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/config/view/ -> PhabricatorSetupIssueView.php (source)

   1  <?php
   2  
   3  final class PhabricatorSetupIssueView extends AphrontView {
   4  
   5    private $issue;
   6  
   7    public function setIssue(PhabricatorSetupIssue $issue) {
   8      $this->issue = $issue;
   9      return $this;
  10    }
  11  
  12    public function getIssue() {
  13      return $this->issue;
  14    }
  15  
  16    public function render() {
  17      $issue = $this->getIssue();
  18  
  19      $description = array();
  20      $description[] = phutil_tag(
  21        'div',
  22        array(
  23          'class' => 'setup-issue-instructions',
  24        ),
  25        phutil_escape_html_newlines($issue->getMessage()));
  26  
  27      $configs = $issue->getPHPConfig();
  28      if ($configs) {
  29        $description[] = $this->renderPHPConfig($configs, $issue);
  30      }
  31  
  32      $configs = $issue->getMySQLConfig();
  33      if ($configs) {
  34        $description[] = $this->renderMySQLConfig($configs);
  35      }
  36  
  37      $configs = $issue->getPhabricatorConfig();
  38      if ($configs) {
  39        $description[] = $this->renderPhabricatorConfig($configs);
  40      }
  41  
  42      $related_configs = $issue->getRelatedPhabricatorConfig();
  43      if ($related_configs) {
  44        $description[] = $this->renderPhabricatorConfig($related_configs,
  45          $related = true);
  46      }
  47  
  48      $commands = $issue->getCommands();
  49      if ($commands) {
  50        $run_these = pht('Run these %d command(s):', count($commands));
  51        $description[] = phutil_tag(
  52          'div',
  53          array(
  54            'class' => 'setup-issue-config',
  55          ),
  56          array(
  57            phutil_tag('p', array(), $run_these),
  58            phutil_tag('pre', array(), phutil_implode_html("\n", $commands)),
  59          ));
  60      }
  61  
  62      $extensions = $issue->getPHPExtensions();
  63      if ($extensions) {
  64        $install_these = pht(
  65          'Install these %d PHP extension(s):', count($extensions));
  66  
  67        $install_info = pht(
  68          'You can usually install a PHP extension using %s or %s. Common '.
  69          'package names are %s or %s. Try commands like these:',
  70          phutil_tag('tt', array(), 'apt-get'),
  71          phutil_tag('tt', array(), 'yum'),
  72          hsprintf('<tt>php-<em>%s</em></tt>', pht('extname')),
  73          hsprintf('<tt>php5-<em>%s</em></tt>', pht('extname')));
  74  
  75        // TODO: We should do a better job of detecting how to install extensions
  76        // on the current system.
  77        $install_commands = hsprintf(
  78          "\$ sudo apt-get install php5-<em>extname</em>  ".
  79          "# Debian / Ubuntu\n".
  80          "\$ sudo yum install php-<em>extname</em>       ".
  81          "# Red Hat / Derivatives");
  82  
  83        $fallback_info = pht(
  84          "If those commands don't work, try Google. The process of installing ".
  85          "PHP extensions is not specific to Phabricator, and any instructions ".
  86          "you can find for installing them on your system should work. On Mac ".
  87          "OS X, you might want to try Homebrew.");
  88  
  89        $restart_info = pht(
  90          'After installing new PHP extensions, <strong>restart your webserver '.
  91          'for the changes to take effect</strong>.',
  92          hsprintf(''));
  93  
  94        $description[] = phutil_tag(
  95          'div',
  96          array(
  97            'class' => 'setup-issue-config',
  98          ),
  99          array(
 100            phutil_tag('p', array(), $install_these),
 101            phutil_tag('pre', array(), implode("\n", $extensions)),
 102            phutil_tag('p', array(), $install_info),
 103            phutil_tag('pre', array(), $install_commands),
 104            phutil_tag('p', array(), $fallback_info),
 105            phutil_tag('p', array(), $restart_info),
 106          ));
 107  
 108      }
 109  
 110      $actions = array();
 111      if (!$issue->getIsFatal()) {
 112        if ($issue->getIsIgnored()) {
 113          $actions[] = javelin_tag(
 114            'a',
 115            array(
 116              'href' => '/config/unignore/'.$issue->getIssueKey().'/',
 117              'sigil' => 'workflow',
 118              'class' => 'button grey',
 119            ),
 120            pht('Unignore Setup Issue'));
 121        } else {
 122          $actions[] = javelin_tag(
 123            'a',
 124            array(
 125              'href' => '/config/ignore/'.$issue->getIssueKey().'/',
 126              'sigil' => 'workflow',
 127              'class' => 'button grey',
 128            ),
 129            pht('Ignore Setup Issue'));
 130        }
 131  
 132        $actions[] = javelin_tag(
 133          'a',
 134          array(
 135            'href' => '/config/issue/'.$issue->getIssueKey().'/',
 136            'class' => 'button grey',
 137            'style' => 'float: right',
 138          ),
 139          pht('Reload Page'));
 140      }
 141  
 142      if ($actions) {
 143        $actions = phutil_tag(
 144          'div',
 145          array(
 146            'class' => 'setup-issue-actions',
 147          ),
 148          $actions);
 149      }
 150  
 151      if ($issue->getIsIgnored()) {
 152        $status = phutil_tag(
 153          'div',
 154          array(
 155            'class' => 'setup-issue-status',
 156          ),
 157          pht(
 158            'This issue is currently ignored, and does not show a global '.
 159            'warning.'));
 160        $next = null;
 161      } else {
 162        $status = null;
 163        $next = phutil_tag(
 164          'div',
 165          array(
 166            'class' => 'setup-issue-next',
 167          ),
 168          pht('To continue, resolve this problem and reload the page.'));
 169      }
 170  
 171      $name = phutil_tag(
 172        'div',
 173        array(
 174          'class' => 'setup-issue-name',
 175        ),
 176        $issue->getName());
 177  
 178      $head = phutil_tag(
 179        'div',
 180        array(
 181          'class' => 'setup-issue-head',
 182        ),
 183        array($name, $status));
 184  
 185      $tail = phutil_tag(
 186        'div',
 187        array(
 188          'class' => 'setup-issue-tail',
 189        ),
 190        array($actions, $next));
 191  
 192      $issue = phutil_tag(
 193        'div',
 194        array(
 195          'class' => 'setup-issue',
 196        ),
 197        array(
 198          $head,
 199          $description,
 200          $tail,
 201        ));
 202  
 203      $debug_info = phutil_tag(
 204        'div',
 205        array(
 206          'class' => 'setup-issue-debug',
 207        ),
 208        pht('Host: %s', php_uname('n')));
 209  
 210      return phutil_tag(
 211        'div',
 212        array(
 213          'class' => 'setup-issue-shell',
 214        ),
 215        array(
 216          $issue,
 217          $debug_info,
 218        ));
 219    }
 220  
 221    private function renderPhabricatorConfig(array $configs, $related = false) {
 222      $issue = $this->getIssue();
 223  
 224      $table_info = phutil_tag(
 225        'p',
 226        array(),
 227        pht(
 228          'The current Phabricator configuration has these %d value(s):',
 229          count($configs)));
 230  
 231      $options = PhabricatorApplicationConfigOptions::loadAllOptions();
 232      $hidden = array();
 233      foreach ($options as $key => $option) {
 234        if ($option->getHidden()) {
 235          $hidden[$key] = true;
 236        }
 237      }
 238  
 239      $table = null;
 240      $dict = array();
 241      foreach ($configs as $key) {
 242        if (isset($hidden[$key])) {
 243          $dict[$key] = null;
 244        } else {
 245          $dict[$key] = PhabricatorEnv::getUnrepairedEnvConfig($key);
 246        }
 247      }
 248  
 249      $table = $this->renderValueTable($dict, $hidden);
 250  
 251      if ($this->getIssue()->getIsFatal()) {
 252        $update_info = phutil_tag(
 253          'p',
 254          array(),
 255          pht(
 256            'To update these %d value(s), run these command(s) from the command '.
 257            'line:',
 258            count($configs)));
 259  
 260        $update = array();
 261        foreach ($configs as $key) {
 262          $update[] = hsprintf(
 263            '<tt>phabricator/ $</tt> ./bin/config set %s <em>value</em>',
 264            $key);
 265        }
 266        $update = phutil_tag('pre', array(), phutil_implode_html("\n", $update));
 267      } else {
 268        $update = array();
 269        foreach ($configs as $config) {
 270          if (idx($options, $config) && $options[$config]->getLocked()) {
 271            continue;
 272          }
 273          $link = phutil_tag(
 274            'a',
 275            array(
 276              'href' => '/config/edit/'.$config.'/?issue='.$issue->getIssueKey(),
 277            ),
 278            pht('Edit %s', $config));
 279          $update[] = phutil_tag('li', array(), $link);
 280        }
 281        if ($update) {
 282          $update = phutil_tag('ul', array(), $update);
 283          if (!$related) {
 284  
 285            $update_info = phutil_tag(
 286            'p',
 287            array(),
 288            pht('You can update these %d value(s) here:', count($configs)));
 289          } else {
 290            $update_info = phutil_tag(
 291            'p',
 292            array(),
 293            pht('These %d configuration value(s) are related:', count($configs)));
 294          }
 295        } else {
 296          $update = null;
 297          $update_info = null;
 298        }
 299      }
 300  
 301      return phutil_tag(
 302        'div',
 303        array(
 304          'class' => 'setup-issue-config',
 305        ),
 306        array(
 307          $table_info,
 308          $table,
 309          $update_info,
 310          $update,
 311        ));
 312    }
 313  
 314    private function renderPHPConfig(array $configs, $issue) {
 315      $table_info = phutil_tag(
 316        'p',
 317        array(),
 318        pht(
 319          'The current PHP configuration has these %d value(s):',
 320          count($configs)));
 321  
 322      $dict = array();
 323      foreach ($configs as $key) {
 324        $dict[$key] = $issue->getPHPConfigOriginalValue(
 325          $key,
 326          ini_get($key));
 327      }
 328  
 329      $table = $this->renderValueTable($dict);
 330  
 331      ob_start();
 332        phpinfo();
 333      $phpinfo = ob_get_clean();
 334  
 335  
 336      $rex = '@Loaded Configuration File\s*</td><td class="v">(.*?)</td>@i';
 337      $matches = null;
 338  
 339      $ini_loc = null;
 340      if (preg_match($rex, $phpinfo, $matches)) {
 341        $ini_loc = trim($matches[1]);
 342      }
 343  
 344      $rex = '@Additional \.ini files parsed\s*</td><td class="v">(.*?)</td>@i';
 345  
 346      $more_loc = array();
 347      if (preg_match($rex, $phpinfo, $matches)) {
 348        $more_loc = trim($matches[1]);
 349        if ($more_loc == '(none)') {
 350          $more_loc = array();
 351        } else {
 352          $more_loc = preg_split('/\s*,\s*/', $more_loc);
 353        }
 354      }
 355  
 356      $info = array();
 357      if (!$ini_loc) {
 358        $info[] = phutil_tag(
 359          'p',
 360          array(),
 361          pht(
 362            'To update these %d value(s), edit your PHP configuration file.',
 363            count($configs)));
 364      } else {
 365        $info[] = phutil_tag(
 366          'p',
 367          array(),
 368          pht(
 369            'To update these %d value(s), edit your PHP configuration file, '.
 370            'located here:',
 371            count($configs)));
 372        $info[] = phutil_tag(
 373          'pre',
 374          array(),
 375          $ini_loc);
 376      }
 377  
 378      if ($more_loc) {
 379        $info[] = phutil_tag(
 380          'p',
 381          array(),
 382          pht(
 383            'PHP also loaded these configuration file(s):',
 384            count($more_loc)));
 385        $info[] = phutil_tag(
 386          'pre',
 387          array(),
 388          implode("\n", $more_loc));
 389      }
 390  
 391      $info[] = phutil_tag(
 392        'p',
 393        array(),
 394        pht(
 395          'You can find more information about PHP configuration values in the '.
 396          '%s.',
 397          phutil_tag(
 398            'a',
 399            array(
 400              'href' => 'http://php.net/manual/ini.list.php',
 401              'target' => '_blank',
 402            ),
 403            pht('PHP Documentation'))));
 404  
 405      $info[] = phutil_tag(
 406        'p',
 407        array(),
 408        pht(
 409          'After editing the PHP configuration, <strong>restart your '.
 410          'webserver for the changes to take effect</strong>.',
 411          hsprintf('')));
 412  
 413      return phutil_tag(
 414        'div',
 415        array(
 416          'class' => 'setup-issue-config',
 417        ),
 418        array(
 419          $table_info,
 420          $table,
 421          $info,
 422        ));
 423    }
 424  
 425    private function renderMySQLConfig(array $config) {
 426      $values = array();
 427      foreach ($config as $key) {
 428        $value = PhabricatorSetupCheckMySQL::loadRawConfigValue($key);
 429        if ($value === null) {
 430          $value = phutil_tag(
 431            'em',
 432            array(),
 433            pht('(Not Supported)'));
 434        }
 435        $values[$key] = $value;
 436      }
 437  
 438      $table = $this->renderValueTable($values);
 439  
 440      $doc_href = PhabricatorEnv::getDoclink('User Guide: Amazon RDS');
 441      $doc_link = phutil_tag(
 442        'a',
 443        array(
 444          'href' => $doc_href,
 445          'target' => '_blank',
 446        ),
 447        pht('User Guide: Amazon RDS'));
 448  
 449      $info = array();
 450      $info[] = phutil_tag(
 451        'p',
 452        array(),
 453        pht(
 454          'If you are using Amazon RDS, some of the instructions above may '.
 455          'not apply to you. See %s for discussion of Amazon RDS.',
 456          $doc_link));
 457  
 458      $table_info = phutil_tag(
 459        'p',
 460        array(),
 461        pht(
 462          'The current MySQL configuration has these %d value(s):',
 463          count($config)));
 464  
 465      return phutil_tag(
 466        'div',
 467        array(
 468          'class' => 'setup-issue-config',
 469        ),
 470        array(
 471          $table_info,
 472          $table,
 473          $info,
 474        ));
 475    }
 476  
 477    private function renderValueTable(array $dict, array $hidden = array()) {
 478      $rows = array();
 479      foreach ($dict as $key => $value) {
 480        if (isset($hidden[$key])) {
 481          $value = phutil_tag('em', array(), 'hidden');
 482        } else {
 483          $value = $this->renderValueForDisplay($value);
 484        }
 485  
 486        $cols = array(
 487          phutil_tag('th', array(), $key),
 488          phutil_tag('td', array(), $value),
 489        );
 490        $rows[] = phutil_tag('tr', array(), $cols);
 491      }
 492      return phutil_tag('table', array(), $rows);
 493    }
 494  
 495    private function renderValueForDisplay($value) {
 496      if ($value === null) {
 497        return phutil_tag('em', array(), 'null');
 498      } else if ($value === false) {
 499        return phutil_tag('em', array(), 'false');
 500      } else if ($value === true) {
 501        return phutil_tag('em', array(), 'true');
 502      } else if ($value === '') {
 503        return phutil_tag('em', array(), 'empty string');
 504      } else if ($value instanceof PhutilSafeHTML) {
 505        return $value;
 506      } else {
 507        return PhabricatorConfigJSON::prettyPrintJSON($value);
 508      }
 509    }
 510  
 511  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1