create fetch form remote in importer
This commit is contained in:
parent
fe215d7116
commit
8dd729092c
|
@ -70,16 +70,19 @@ abstract class Importer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* get the content form url and creates a file
|
||||||
|
*
|
||||||
* @param $url
|
* @param $url
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function fetch_from_remote( $url ){
|
public function fetch_from_remote( $url ){
|
||||||
$tmp = download_url( $url );
|
$tmp = wp_remote_get( $url );
|
||||||
$path_parts = pathinfo( $url );
|
if( isset( $tmp['body'] ) ){
|
||||||
|
$file = fopen( $this->get_id().'.txt', 'w' );
|
||||||
$file_array['name'] = $path_parts['basename'];
|
fwrite( $file, $tmp['body'] );
|
||||||
$file_array['tmp_name'] = $tmp;
|
fclose( $file );
|
||||||
$file_array['size'] = filesize( $tmp );
|
return $this->set_file( $this->get_id().'.txt' );
|
||||||
return media_handle_sideload( $file_array, 0 );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -68,4 +68,14 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
||||||
// here the session is init already
|
// here the session is init already
|
||||||
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group importer
|
||||||
|
*/
|
||||||
|
public function test_fetch_file(){
|
||||||
|
$csv_importer = new Importer\CSV();
|
||||||
|
$id = $csv_importer->get_id();
|
||||||
|
$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wordpress-test/wp-json' );
|
||||||
|
$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) );
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue