1717use Cake \Datasource \ConnectionInterface ;
1818use Cake \Datasource \ConnectionManager ;
1919use InvalidArgumentException ;
20- use RuntimeException ;
2120use Symfony \Component \Filesystem \Filesystem ;
2221
2322/**
@@ -30,32 +29,20 @@ trait BackupTrait
3029 * @since 2.4.0
3130 * @var array
3231 */
33- private static $ validExtensions = ['sql.bz2 ' => 'bzip2 ' , 'sql.gz ' => 'gzip ' , 'sql ' => false ];
32+ protected static $ validExtensions = ['sql.bz2 ' => 'bzip2 ' , 'sql.gz ' => 'gzip ' , 'sql ' => false ];
3433
3534 /**
3635 * Returns an absolute path
3736 * @param string $path Relative or absolute path
3837 * @return string
39- * @uses getTarget()
4038 */
4139 public function getAbsolutePath ($ path )
4240 {
43- return (new Filesystem ())->isAbsolutePath ($ path ) ? $ path : add_slash_term ($ this ->getTarget ()) . $ path ;
44- }
45-
46- /**
47- * Gets a binary path
48- * @param string $name Binary name
49- * @return string
50- * @since 2.0.0
51- * @throws \RuntimeException
52- */
53- public function getBinary ($ name )
54- {
55- $ binary = Configure::read ('DatabaseBackup.binaries. ' . $ name );
56- is_true_or_fail ($ binary , __d ('database_backup ' , 'Binary for `{0}` could not be found. You have to set its path manually ' , $ name ), RuntimeException::class);
41+ if (!(new Filesystem ())->isAbsolutePath ($ path )) {
42+ return add_slash_term (Configure::read ('DatabaseBackup.target ' )) . $ path ;
43+ }
5744
58- return $ binary ;
45+ return $ path ;
5946 }
6047
6148 /**
@@ -92,12 +79,11 @@ public function getConnection($name = null)
9279 * @since 2.0.0
9380 * @throws \InvalidArgumentException
9481 * @uses getConnection()
95- * @uses getDriverName()
9682 */
9783 public function getDriver (ConnectionInterface $ connection = null )
9884 {
9985 $ connection = $ connection ?: $ this ->getConnection ();
100- $ className = $ this -> getDriverName ( $ connection );
86+ $ className = get_class_short_name ( $ connection -> getDriver () );
10187 $ driver = App::classname (sprintf ('%s.%s ' , 'DatabaseBackup ' , $ className ), 'Driver ' );
10288 is_true_or_fail (
10389 $ driver ,
@@ -108,41 +94,18 @@ public function getDriver(ConnectionInterface $connection = null)
10894 return new $ driver ($ connection );
10995 }
11096
111- /**
112- * Gets the driver name, according to the database engine
113- * @param \Cake\Datasource\ConnectionInterface|null $connection A connection object
114- * @return string The driver name
115- * @since 2.6.2
116- * @uses getConnection()
117- */
118- public function getDriverName (ConnectionInterface $ connection = null )
119- {
120- $ connection = $ connection ?: $ this ->getConnection ();
121-
122- return get_class_short_name ($ connection ->getDriver ());
123- }
124-
12597 /**
12698 * Returns the extension from a filename
12799 * @param string $filename Filename
128100 * @return string|null Extension or `null` if the extension is not found or
129101 * if is an invalid extension
130- * @uses getValidExtensions()
102+ * @uses $validExtensions
131103 */
132104 public function getExtension ($ filename )
133105 {
134106 $ extension = get_extension ($ filename );
135107
136- return in_array ($ extension , $ this ->getValidExtensions ()) ? $ extension : null ;
137- }
138-
139- /**
140- * Returns the target path
141- * @return string
142- */
143- public function getTarget ()
144- {
145- return Configure::read ('DatabaseBackup.target ' );
108+ return in_array ($ extension , array_keys (self ::$ validExtensions )) ? $ extension : null ;
146109 }
147110
148111 /**
@@ -155,15 +118,4 @@ public function getValidCompressions()
155118 {
156119 return array_filter (self ::$ validExtensions );
157120 }
158-
159- /**
160- * Returns all valid extensions
161- * @return array
162- * @since 2.4.0
163- * @uses $validExtensions
164- */
165- public function getValidExtensions ()
166- {
167- return array_keys (self ::$ validExtensions );
168- }
169121}
0 commit comments