Skip to content

Commit

Permalink
removing file_get_contents() usages (#992)
Browse files Browse the repository at this point in the history
* removing file_get_contents() usages

* allowing build.txt to be include in the storage path
  • Loading branch information
dgershman authored Mar 30, 2024
1 parent 750ef2a commit 6c3b621
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
DISABLE_NOTIFIER=true make deploy
unzip ${ARTIFACT_FILENAME}
rm ${ARTIFACT_FILENAME}
echo ${GITHUB_SHA} > ${ARTIFACT_FILE}/build.txt
echo ${GITHUB_SHA} > ${ARTIFACT_FILE}/storage/app/build.txt
cp -R vendor ${ARTIFACT_FILE}/
mkdir -p ${ARTIFACT_FILE}/public/dist && cp -R public/dist/. ${ARTIFACT_FILE}/public/dist
find ./${ARTIFACT_FILE} -type d | xargs chmod 755
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unstable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
DISABLE_NOTIFIER=true make deploy
unzip ${ARTIFACT_FILENAME}
rm ${ARTIFACT_FILENAME}
echo ${GITHUB_SHA} > ${ARTIFACT_FILE}/build.txt
echo ${GITHUB_SHA} > ${ARTIFACT_FILE}/storage/app/build.txt
cp -R vendor ${ARTIFACT_FILE}/
mkdir -p ${ARTIFACT_FILE}/public/dist && cp -R public/dist/. ${ARTIFACT_FILE}/public/dist
find ./${ARTIFACT_FILE} -type d | xargs chmod 755
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ For setup instructions and general documentation please visit [https://yap.bmlt.

# ⚠️ Major Refactor

Currently we are in the process of doing a major overhaul of the codebase, by migrating all the legacy PHP to a more Laravel-like structure. This will improve the stability and maintainability. Also, as part of this change, we are making the code more testable which will help us track code paths more effectively. We also plan to redo the frontend part of it migrating from a Bootstrap/Jquery structure to React.

All the legacy components has been migrated. We are doing some final testing now.
Currently we are in the process of doing a major overhaul of the codebase. This will improve the stability and maintainability. Also, as part of this change, we are making the code more testable which will help us track code paths more effectively. All the PHP code has been migrated, however there are some remaining database components that are not in a Laravel-like structure.

In a future release we will refactor the frontend by building a new React application to consume the rebuilt APIs, that work has partially started but has been put on pause.

Expand Down
1 change: 1 addition & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 4.3.3 (UNRELEASED)
* Fix for reports where they are always recursing service bodies regardless of the setting [#980]
* Fix for metrics counts summaries.
* Removing `file_get_contents()` usage to support some cases where servers may be misconfigured.
* Using native Laravel database migrations.

### 4.3.2 (March 21, 2024)
Expand Down
40 changes: 23 additions & 17 deletions app/Http/Controllers/VoicemailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Constants\EventId;
use App\Constants\VolunteerResponderOption;
use App\Exceptions\NoVolunteersException;
use App\Services\CallService;
use App\Services\ConfigService;
use App\Services\RootServerService;
Expand All @@ -12,6 +13,7 @@
use App\Services\VoicemailService;
use App\Services\VolunteerService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Twilio\TwiML\VoiceResponse;

class VoicemailController extends Controller
Expand Down Expand Up @@ -101,24 +103,28 @@ public function complete(Request $request)
);
}

if (isset($_SESSION["volunteer_routing_parameters"])) {
$volunteer_routing_options = $_SESSION["volunteer_routing_parameters"];
$volunteer_routing_options->volunteer_responder = VolunteerResponderOption::ENABLED;
$volunteers = $this->volunteers->getHelplineVolunteersActiveNow($volunteer_routing_options);
$recipients = [];
foreach ($volunteers as $volunteer) {
$recipients[] = $volunteer->contact;
}
if (count($volunteers) > 0) {
$this->voicemail->sendSmsForVoicemail(
$callSid,
$recordingUrl,
$recipients,
$serviceBodyCallHandling,
$serviceBodyName,
$callerNumber
);
try {
if (isset($_SESSION["volunteer_routing_parameters"])) {
$volunteer_routing_options = $_SESSION["volunteer_routing_parameters"];
$volunteer_routing_options->volunteer_responder = VolunteerResponderOption::ENABLED;
$volunteers = $this->volunteers->getHelplineVolunteersActiveNow($volunteer_routing_options);
$recipients = [];
foreach ($volunteers as $volunteer) {
$recipients[] = $volunteer->contact;
}
if (count($volunteers) > 0) {
$this->voicemail->sendSmsForVoicemail(
$callSid,
$recordingUrl,
$recipients,
$serviceBodyCallHandling,
$serviceBodyName,
$callerNumber
);
}
}
} catch (NoVolunteersException $nve) {
Log::debug("complete() :: " . $nve);
}

if ($serviceBodyCallHandling->primary_contact_email_enabled && $this->settings->has('smtp_host')) {
Expand Down
33 changes: 0 additions & 33 deletions app/Services/DatabaseMigrationsService.php

This file was deleted.

3 changes: 2 additions & 1 deletion app/Services/UpgradeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class UpgradeService extends Service
{
Expand Down Expand Up @@ -123,7 +124,7 @@ public function getStatus()
private function getState($status = null, $message = null, $warnings = "")
{
try {
$build = file_get_contents("build.txt", false);
$build = Storage::get("build.txt");
} catch (Exception $e) {
$build = $e->getMessage();
}
Expand Down
7 changes: 5 additions & 2 deletions app/Services/VoicemailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Constants\SmtpPorts;
use Exception;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use PHPMailer\PHPMailer\PHPMailer;
use App\Constants\SmsDialbackOptions;
Expand Down Expand Up @@ -65,12 +66,14 @@ public function sendEmailForVoicemail($recordingUrl, $recipients, $serviceBodyNa
foreach ($recipients as $recipient) {
$this->mailer->addAddress($recipient);
}
$this->mailer->addStringAttachment(file_get_contents($recordingUrl . ".mp3"), $recordingUrl . ".mp3");
$recordingUrlWithExtension = sprintf("%s.mp3", $recordingUrl);
$recordingDataString = Http::get($recordingUrlWithExtension);
$this->mailer->addStringAttachment($recordingDataString, $recordingUrlWithExtension);
$this->mailer->Body = "You have a message from the " . $serviceBodyName . " helpline from caller " . $callerNumber . ", " . $recordingUrl. ".mp3";
$this->mailer->Subject = 'Helpline Voicemail from ' . $serviceBodyName;
$this->mailer->send();
} catch (Exception $e) {
Log::critical('Message could not be sent. Mailer Error: ' . $this->mailer->ErrorInfo);
Log::critical('Message could not be sent. Mailer Error: ' . $e);
}
}
}
1 change: 1 addition & 0 deletions storage/app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!public/
!.gitignore
!build.txt
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/Feature/VoicemailCompleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
$this->utility = setupTwilioService();
$this->callSid = "abc123";
$this->callerNumber = "+17325551212";
$this->recordingUrl = "file:///".getcwd()."/tests/fake";
$this->recordingUrl = "https://example.org/tests/fake";
$expectedPin = 4182804;

$reportsRepository = mock(ReportsRepository::class)->makePartial();
Expand Down Expand Up @@ -184,10 +184,10 @@
$callContextMock->shouldReceive('update')
->with(Mockery::on(function ($data) {
return $data['status'] == TwilioCallStatus::COMPLETED;
}));
}))->once();
$this->utility->client->shouldReceive('calls')
->with($this->callSid)
->andReturn($callContextMock);
->andReturn($callContextMock)->once();

$repository = Mockery::mock(ConfigRepository::class);
$repository->shouldReceive("getDbData")->with(
Expand Down

0 comments on commit 6c3b621

Please sign in to comment.