Skip to content

Commit 5617ab9

Browse files
Merge pull request #34 from mrrobot47/update/to-utility-function
Update to utility functions
2 parents 7481d84 + 1f6a475 commit 5617ab9

1 file changed

Lines changed: 9 additions & 45 deletions

File tree

src/Admin_Tools_Command.php

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use EE\Model\Site;
1010
use Symfony\Component\Filesystem\Filesystem;
1111
use function EE\Site\Utils\auto_site_name;
12+
use function EE\Utils\download;
13+
use function EE\Utils\extract_zip;
1214

1315
class Admin_Tools_Command extends EE_Command {
1416

@@ -197,44 +199,6 @@ private function is_installed( $tool = '' ) {
197199
return $this->fs->exists( ADMIN_TOOL_DIR . '/' . $tool );
198200
}
199201

200-
/**
201-
* Function to download file to a path.
202-
*
203-
* @param string $path Path to download the file on.
204-
* @param string $download_url Url to download the file from.
205-
*/
206-
private function download( $path, $download_url ) {
207-
208-
$headers = array();
209-
$options = array(
210-
'timeout' => 1200, // 20 minutes ought to be enough for everybody.
211-
'filename' => $path,
212-
);
213-
EE\Utils\http_request( 'GET', $download_url, null, $headers, $options );
214-
}
215-
216-
/**
217-
* Extract zip files.
218-
*
219-
* @param string $zip_file Path to the zip file.
220-
* @param string $path_to_extract Path where zip needs to be extracted to.
221-
*
222-
* @return bool Success of extraction.
223-
*/
224-
private function extract_zip( $zip_file, $path_to_extract ) {
225-
226-
$zip = new ZipArchive;
227-
$res = $zip->open( $zip_file );
228-
if ( true === $res ) {
229-
$zip->extractTo( $path_to_extract );
230-
$zip->close();
231-
232-
return true;
233-
}
234-
235-
return false;
236-
}
237-
238202
/**
239203
* Place config files from templates to tools.
240204
*
@@ -285,8 +249,8 @@ private function install_pma( $data, $tool_path ) {
285249
$download_path = $temp_dir . 'pma.zip';
286250
$unzip_folder = $temp_dir . '/pma';
287251
$this->fs->remove( [ $download_path, $unzip_folder ] );
288-
$this->download( $download_path, $data['url'] );
289-
$this->extract_zip( $download_path, $unzip_folder );
252+
download( $download_path, $data['url'] );
253+
extract_zip( $download_path, $unzip_folder );
290254
$zip_folder_name = scandir( $unzip_folder );
291255
$this->fs->rename( $unzip_folder . '/' . array_pop( $zip_folder_name ), $tool_path );
292256
$this->move_config_file( 'pma.config.mustache', $tool_path . '/config.inc.php' );
@@ -306,14 +270,14 @@ private function install_pra( $data, $tool_path ) {
306270
$this->fs->remove( [ $download_path, $unzip_folder ] );
307271
$vendor_zip = $temp_dir . 'vendor.zip';
308272
$download_url = str_replace( '{version}', $data['version'], $data['url'] );
309-
$this->download( $download_path, $download_url );
310-
$this->extract_zip( $download_path, $unzip_folder );
273+
download( $download_path, $download_url );
274+
extract_zip( $download_path, $unzip_folder );
311275
$zip_folder_name = scandir( $unzip_folder );
312276
$pra_root_folder = $unzip_folder . '/' . array_pop( $zip_folder_name );
313277
$vendor_path = $pra_root_folder . '/vendor';
314278
$vendor_requirement_url = 'https://github.com/nrk/predis/archive/v1.1.1.zip';
315-
$this->download( $vendor_zip, $vendor_requirement_url );
316-
$this->extract_zip( $vendor_zip, $pra_root_folder );
279+
download( $vendor_zip, $vendor_requirement_url );
280+
extract_zip( $vendor_zip, $pra_root_folder );
317281
$this->fs->rename( $pra_root_folder . '/predis-1.1.1', $vendor_path );
318282
$this->fs->rename( $pra_root_folder, $tool_path );
319283
$this->move_config_file( 'pra.config.mustache', $tool_path . '/includes/config.inc.php' );
@@ -330,7 +294,7 @@ private function install_opcache( $data, $tool_path ) {
330294
$temp_dir = EE\Utils\get_temp_dir();
331295
$download_path = $temp_dir . 'opcache-gui.php';
332296
$this->fs->remove( $download_path );
333-
$this->download( $download_path, $data['url'] );
297+
download( $download_path, $data['url'] );
334298
$this->fs->rename( $temp_dir . 'opcache-gui.php', $tool_path . '-gui.php' );
335299
}
336300

0 commit comments

Comments
 (0)