Changeset 11230
- Timestamp:
- 09/14/2021 06:38:51 AM (5 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory
- Files:
-
- 1 added
- 1 edited
-
class-wporg-themes-upload.php (modified) (3 diffs)
-
lib/class-exec-with-logging.php (added)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php
r11229 r11230 1 1 <?php 2 2 use WordPressdotorg\Theme_Directory\Lib\GitHub; 3 use WordPressdotorg\Theme_Directory\Lib\Exec_With_Logging; 3 4 4 5 /** … … 8 9 */ 9 10 class WPORG_Themes_Upload { 11 use Exec_With_Logging { 12 Exec_With_Logging::exec as exec_with_notify; 13 } 14 10 15 /** 11 16 * Path to `svn` script. … … 1623 1628 protected function sort_by_string_length( $a, $b ) { 1624 1629 return strlen( $b ) - strlen( $a ); 1625 }1626 1627 /**1628 * Execute a shell process, same behaviour as `exec()` but with PHP Warnings/Notices generated on errors.1629 *1630 * @param string $command Command to execute. Escape it.1631 * @param array $output Array to append program output to. Passed by reference.1632 * @param int $return_var The commands return value. Passed by reference.1633 *1634 * @return false|string False on failure, last line of output on success, as per exec().1635 */1636 public function exec_with_notify( $command, &$output = null, &$return_var = null ) {1637 $proc = proc_open(1638 $command,1639 [1640 1 => [ 'pipe', 'w' ], // STDOUT1641 2 => [ 'pipe', 'w' ], // STDERR1642 ],1643 $pipes1644 );1645 1646 $stdout = stream_get_contents( $pipes[1] );1647 $stderr = stream_get_contents( $pipes[2] );1648 fclose( $pipes[1] );1649 fclose( $pipes[2] );1650 1651 $return_var = proc_close( $proc );1652 1653 // Append to $output, as `exec()` does.1654 if ( ! is_array( $output ) ) {1655 $output = [];1656 }1657 if ( $stdout ) {1658 $output = array_merge( $output, explode( "\n", rtrim( $stdout, "\r\n" ) ) );1659 }1660 1661 // Redact any passwords that might be in a command and included in logged errors.1662 $command = str_replace( [ THEME_TRACBOT_PASSWORD, THEME_DROPBOX_PASSWORD ], '[redacted]', $command );1663 1664 if ( $return_var > 0 ) {1665 trigger_error(1666 "Command failed, `{$command}`\n" .1667 "```\n" .1668 "Return Value: {$return_var}\n" .1669 "STDOUT: {$stdout}\n" .1670 "STDERR: {$stderr}\n" .1671 "```",1672 E_USER_WARNING1673 );1674 } elseif ( $stderr ) {1675 trigger_error(1676 "Command produced errors, `{$command}`\n" .1677 "```\n" .1678 "Return Value: {$return_var}\n" .1679 "STDOUT: {$stdout}\n" .1680 "STDERR: {$stderr}\n" .1681 "```",1682 E_USER_NOTICE1683 );1684 }1685 1686 // Execution failed.1687 if ( $return_var > 0 ) {1688 return false;1689 }1690 1691 // Successful, return the last output line.1692 return $stdout ? end( $output ) : '';1693 1630 } 1694 1631
Note: See TracChangeset
for help on using the changeset viewer.