r69161 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69160‎ | r69161 | r69162 >
Date:22:16, 7 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Work on porting WP filesystem abstraction classes
Modified paths:
  • /trunk/extensions/Deployment/Deployment.i18n.php (modified) (history)
  • /trunk/extensions/Deployment/includes/filesystems/FtpFilesystem.php (modified) (history)
  • /trunk/extensions/Deployment/includes/filesystems/Ssh2Filesystem.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Deployment/Deployment.i18n.php
@@ -34,8 +34,9 @@
3535 'deploy-ssh2-username-required' => 'SSH username is required',
3636 'deploy-ssh2-password-required' => 'SSH password or private key is required',
3737 'deploy-ssh2-hostname-required' => 'SSH hostname is required',
38 - 'deploy-ftp-connect-failed' => 'Failed to connect to SSH2 server $1:$2',
 38+ 'deploy-ssh2-connect-failed' => 'Failed to connect to SSH2 server $1:$2',
3939 'deploy-ssh2-key-authentication-failed' => 'Public and private keys are incorrect for username $1',
4040 'deploy-ssh2-password-authentication-failed' => 'Username or password incorrect for username $1',
 41+ 'deploy-ssh2-command-failed' => 'Unable to perform command: $1',
4142
4243 );
Index: trunk/extensions/Deployment/includes/filesystems/FtpFilesystem.php
@@ -27,9 +27,9 @@
2828 /**
2929 * The FTP connection link.
3030 *
31 - * @var resource
 31+ * @var FTP resource or false
3232 */
33 - protected $connection;
 33+ protected $connection = false;
3434
3535 /**
3636 * Constructor.
Index: trunk/extensions/Deployment/includes/filesystems/Ssh2Filesystem.php
@@ -27,9 +27,9 @@
2828 /**
2929 * The FTP connection link.
3030 *
31 - * @var FTP resource
 31+ * @var FTP resource or false
3232 */
33 - protected $connection;
 33+ protected $connection = false;
3434
3535 /**
3636 * The SFTP connection link.
@@ -95,6 +95,10 @@
9696 $options['port'] = 21;
9797 }
9898
 99+ if ( !array_key_exists( 'timeout', $options ) ) {
 100+ $options['timeout'] = 240;
 101+ }
 102+
99103 // Store the options.
100104 $this->options = $options;
101105 }
@@ -119,7 +123,7 @@
120124 }
121125
122126 if ( $this->publicKeyAuthentication ) {
123 - $ssh2_auth_pubkey_file = ssh2_auth_pubkey_file($this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] );
 127+ $ssh2_auth_pubkey_file = ssh2_auth_pubkey_file( $this->link, $this->options['username'], $this->options['public_key'], $this->options['private_key'], $this->options['password'] );
124128
125129 if ( !$ssh2_auth_pubkey_file ) {
126130 $this->addErrorMessage( wfMsgExt( 'deploy-ssh2-key-authentication-failed', $this->options['username'] ) );
@@ -308,4 +312,30 @@
309313
310314 }
311315
 316+ /**
 317+ * Executes a command.
 318+ *
 319+ * @param string $command
 320+ */
 321+ protected function runCommand( $command ) {
 322+ if ( !$this->connection ) {
 323+ return false;
 324+ }
 325+
 326+ if ( $stream = ssh2_exec( $this->connection, $command ) ) {
 327+ stream_set_blocking( $stream, true );
 328+ stream_set_timeout( $stream, $this->options['timeout'] );
 329+
 330+ $data = stream_get_contents( $stream );
 331+
 332+ fclose( $stream );
 333+
 334+ return $data;
 335+ }
 336+ else {
 337+ $this->addErrorMessage( wfMsgExt( 'deploy-ssh2-command-failed', $command ) );
 338+ return false;
 339+ }
 340+ }
 341+
312342 }
\ No newline at end of file

Status & tagging log