add: tests
This commit is contained in:
parent
eebf859afa
commit
ce7f620984
16 changed files with 681 additions and 152 deletions
48
app/Http/Controllers/ThirdPartyServices/NextcloudService.php
Normal file
48
app/Http/Controllers/ThirdPartyServices/NextcloudService.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\ThirdPartyServices;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Mail\sendExportNotice;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use RuntimeException;
|
||||
|
||||
class NextcloudService extends Controller
|
||||
{
|
||||
private $nextcloud_url;
|
||||
private $nextcloud_user;
|
||||
private $nextcloud_password;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->nextcloud_url = env('NEXTCLOUD_URL', false);
|
||||
$this->nextcloud_user = env('NEXTCLOUD_USER', false);
|
||||
$this->nextcloud_password = env('NEXTCLOUD_PASSWORD', false);
|
||||
$this->nextcloud_upload_folder_path = env('NEXTCLOUD_UPLOAD_FOLDER_PATH', false);
|
||||
$this->nextcloud_upload_folder_web_link = env('NEXTCLOUD_UPLOAD_FOLDER_WEB_LINK', false);
|
||||
}
|
||||
|
||||
function nextcloud_upload_csv(string $file_name, string $file_path)
|
||||
{
|
||||
try {
|
||||
$nextcloud_url = $this->nextcloud_url . '/remote.php/dav/files/' . $this->nextcloud_user . '/' . $this->nextcloud_upload_folder_path . '/' . $file_name;
|
||||
$file_contents = fopen($file_path, 'r');
|
||||
try {
|
||||
$res = Http::withBasicAuth($this->nextcloud_user, $this->nextcloud_password)
|
||||
->attach($file_name, $file_contents)
|
||||
->put($nextcloud_url);
|
||||
$res->throw();
|
||||
} catch (\Exception $e) {
|
||||
Log::error('nextcloud_upload_csv Upload error - ' . $e->getMessage());
|
||||
throw new RuntimeException("E-NEXTCLOUD-UPLOAD");
|
||||
}
|
||||
// Close the file handle
|
||||
fclose($file_contents);
|
||||
return $res;
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue