| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace HM\BackUpWordPress; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\Process\Process as Process; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Perform a database backup using the mysqldump cli command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Mysqldump_Database_Backup_Engine extends Database_Backup_Engine { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	 * The path to the mysqldump executable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	 * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	private $mysqldump_executable_path = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	public function __construct() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 	 * Calculate the path to the mysqldump executable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	 * The executable path can be overridden using either the `HMBKP_MYSQLDUMP_PATH` | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	 * Constant or the `hmbkp_mysqldump_executable_path` filter. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * If neither of those are set then we fallback to checking a number of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * common locations. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	 * @return string|false The path to the executable or false. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	public function get_mysqldump_executable_path() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		// Return now if it's set in a Constant | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		if ( defined( 'HMBKP_MYSQLDUMP_PATH' ) && HMBKP_MYSQLDUMP_PATH ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			$this->mysqldump_executable_path = HMBKP_MYSQLDUMP_PATH; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 		/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		 * Allow the executable path to be set via a filter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		 * @param string The path to the mysqldump executable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		$this->mysqldump_executable_path = apply_filters( 'hmbkp_mysqldump_executable_path', '' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		if ( ! $this->mysqldump_executable_path ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 			// List of possible mysqldump locations | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 			$paths = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 				'mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 				'/usr/local/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 				'/usr/local/mysql/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 				'/usr/mysql/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 				'/usr/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 				'/opt/local/lib/mysql6/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 				'/opt/local/lib/mysql5/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 				'/opt/local/lib/mysql4/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 				'/xampp/mysql/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 				'/Program Files/xampp/mysql/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 				'/Program Files/MySQL/MySQL Server 6.0/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 				'/Program Files/MySQL/MySQL Server 5.7/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 				'/Program Files/MySQL/MySQL Server 5.6/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 				'/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 				'/Program Files/MySQL/MySQL Server 5.4/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 				'/Program Files/MySQL/MySQL Server 5.1/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 				'/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 				'/Program Files/MySQL/MySQL Server 4.1/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 				'/opt/local/bin/mysqldump', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 			$this->mysqldump_executable_path = Backup_Utilities::get_executable_path( $paths ); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		return $this->mysqldump_executable_path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	 * Perform the database backup. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	 * @return bool Whether the backup completed successfully or not. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 	public function backup() { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  | 		if ( ! $this->get_mysqldump_executable_path() ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  | 			return false; | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  | 		// Grab the database connections args | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  | 		$args = $this->get_mysql_connection_args(); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  | 		// Allow lock-tables to be overridden | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  | 		if ( defined( 'HMBKP_MYSQLDUMP_SINGLE_TRANSACTION' ) && HMBKP_MYSQLDUMP_SINGLE_TRANSACTION  ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  | 			$args[] = '--single-transaction'; | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  | 		// Make sure binary data is exported properly | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  | 		$args[] = '--hex-blob'; | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  | 		// The file we're saving too | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  | 		$args[] = '-r ' . escapeshellarg( $this->get_backup_filepath() ); | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  | 		// The database we're dumping | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  | 		$args[] = escapeshellarg( $this->get_name() ); | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  | 		$process = new Process( $this->get_mysqldump_executable_path() . ' ' . implode( ' ', $args ) ); | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  | 		$process->setTimeout( HOUR_IN_SECONDS ); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  | 		try { | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  | 			$process->run(); | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  | 		} catch ( \Exception $e ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  | 			$this->error( __CLASS__, $e->getMessage() ); | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  | 		if ( ! $process->isSuccessful() ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  | 			$this->error( __CLASS__, $process->getErrorOutput() ); | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  | 		return $this->verify_backup(); | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 	 * Get the connection args for the mysqldump command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 	 * @return array The array of connection args | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 	public function get_mysql_connection_args() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 		$args = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 		$args[] = '-u ' . escapeshellarg( $this->get_user() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 		if ( $this->get_password() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 			$args[] = '-p' . escapeshellarg( $this->get_password() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 		$args[] = '-h ' . escapeshellarg( $this->get_host() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  | 		if ( $this->get_port() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 			$args[] = '-P ' . escapeshellarg( $this->get_port() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 		if ( $this->get_socket() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 			$args[] = '--protocol=socket -S ' . escapeshellarg( $this->get_socket() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 		return $args; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 154 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 155 |  |  |  | 
            
                        
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.