Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RES-1858 Switch to use mapbox for geocoding #644

Open
wants to merge 171 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
34fd7f6
Merge branch 'develop' into RES-1722_suggest_product_category
edwh Aug 1, 2022
e51a470
Testing feedback.
edwh Aug 1, 2022
e7d90ed
Test fixes.
edwh Aug 1, 2022
f4fc071
Category change zaps item type.
edwh Aug 1, 2022
d2bbf66
Merge branch 'develop' into RES-1722_suggest_product_category
edwh Aug 3, 2022
7bfa34a
Merge branch 'RES-1722_suggest_product_category' into RES-1787_catego…
edwh Nov 9, 2022
98e7887
Merge branch 'develop' into RES-1787_category_suggestion
edwh Nov 9, 2022
53022f9
Merge branch 'develop' into RES-1787_category_suggestion
edwh Feb 20, 2023
2c4bc3e
Change from pulsate to thick border.
edwh Feb 20, 2023
822f769
Merge branch 'develop' into RES-1787_category_suggestion
edwh Mar 10, 2023
323c18f
Not matching on items correctly.
edwh Mar 10, 2023
1d7eea7
Bump webpack from 5.75.0 to 5.76.1
dependabot[bot] Mar 15, 2023
06105d8
Discourse usernames not syncing.
edwh Mar 23, 2023
54ad8e7
Add API call to create event.
edwh Apr 5, 2023
938b509
Add API call for editing an event.
edwh Apr 5, 2023
5b29bc3
Merge branch 'develop' into RES-1787_category_suggestion
ngm Apr 18, 2023
cded09a
Review fixes.
edwh Apr 19, 2023
a8cf493
Merge remote-tracking branch 'origin/RES-1787_category_suggestion' in…
edwh Apr 19, 2023
bdc210f
Change display/hide times of Big Give banner
ngm Apr 19, 2023
1d10da4
Bump nyholm/psr7 from 1.5.1 to 1.8.0
dependabot[bot] May 3, 2023
bebfdbf
Bump guzzlehttp/psr7 from 2.4.3 to 2.5.0
dependabot[bot] May 3, 2023
98aa5d3
Restore files
ngm May 3, 2023
25ef522
Merge branch 'develop'
ngm May 3, 2023
e9af037
Bump engine.io and socket.io
dependabot[bot] May 4, 2023
2b9bd70
Network Coordinator can't create events on other groups they created.
edwh May 5, 2023
6a649e9
Merge branch 'develop' into RES-1795_vue_event_create_edit
edwh May 5, 2023
cad4217
WIP Change add/edit event to use API.
edwh May 5, 2023
ac48ef2
Test fixes.
edwh May 5, 2023
7938488
update_at attribute is returning current time for all events.
edwh May 9, 2023
769c538
Test fixes.
edwh May 9, 2023
f2f37fd
Test fixes.
edwh May 9, 2023
0423eb6
Category_creation field shouldn't be changed when editing a device.
edwh May 9, 2023
2148cfd
Remove useful URLs feature, which wasn't.
edwh May 9, 2023
bd0a716
Test fixes.
edwh May 9, 2023
f151ff7
Tweak compare method to handle e.g. TV better.
edwh May 11, 2023
70d04fb
Update to MySQL 8 as query requires it.
edwh May 11, 2023
90f9bd8
Test fixes.
edwh May 11, 2023
ff9fdca
Revert "Test fixes."
edwh May 11, 2023
da61448
Revert "Update to MySQL 8 as query requires it."
edwh May 11, 2023
5410750
Rework query to work on older MySQL.
edwh May 11, 2023
e7755f1
Add ability to edit network data for groups.
edwh May 11, 2023
f11ca4e
Add translations.
edwh May 11, 2023
d56479d
Minor copy changes on landing page.
edwh May 11, 2023
ed6c8b4
Button to use group location doesn't work.
edwh May 11, 2023
a6d1f78
Coverage of Discourse function.
edwh May 11, 2023
c68d6e3
Coverage of Discourse function.
edwh May 11, 2023
3b72f11
Coverage of Discourse function.
edwh May 15, 2023
f3ae561
Coverage of Discourse function.
edwh May 15, 2023
d64c235
Coverage of Discourse function.
edwh May 15, 2023
311b2e6
Coverage of Discourse function.
edwh May 15, 2023
1dd1753
Coverage of Discourse function.
edwh May 15, 2023
1c03283
Testing feedback.
edwh May 15, 2023
5add3ba
Coverage of Discourse function.
edwh May 15, 2023
7f0179a
Coverage of Discourse function.
edwh May 15, 2023
2336bbe
Testing feedback.
edwh May 15, 2023
98985b3
Add getMaxUpdatedAtDevicesUpdatedAtAttribute back in (removed in error)
edwh May 17, 2023
7d1d45e
Merge pull request #652 from TheRestartProject/RES-1893_landing_page_…
edwh May 17, 2023
479e3df
Merge pull request #649 from TheRestartProject/RES-1888_category_change
edwh May 17, 2023
090c158
Add migration.
edwh May 17, 2023
7ffc777
Merge pull request #646 from TheRestartProject/RES-1891_network_coord…
edwh May 17, 2023
3abfe52
Merge pull request #651 from TheRestartProject/RES-1892_edit_network_…
edwh May 17, 2023
a4af958
Can't add network data if none already.
edwh May 17, 2023
dc7d78f
Merge branch 'RES-1892_edit_network_data' into develop
edwh May 17, 2023
013b73a
Merge branch 'develop' into RES-1795_vue_event_create_edit
edwh May 17, 2023
da0643d
Retire dead code about creating user lists.
edwh May 17, 2023
71d1830
Coding conventions.
edwh May 17, 2023
0d65abe
Merge pull request #630 from TheRestartProject/RES-1866_username_sync
edwh May 17, 2023
b60b641
Test fixes.
edwh May 17, 2023
073e751
NetworkCoordinator sees create event option but can't actually create.
edwh May 17, 2023
7c2dfc6
Add test for time format.
edwh May 17, 2023
4cafbde
Merge pull request #654 from TheRestartProject/RES-1891_network_coord…
edwh May 22, 2023
0039225
Merge pull request #636 from TheRestartProject/RES-1795_vue_event_cre…
edwh May 22, 2023
c4f80e7
Merge branch 'develop' into RES-1882_sentry
edwh May 22, 2023
aca785c
Merge branch 'develop' into RES-1890_updated_at_incorrect_for_events
edwh May 22, 2023
6348865
Merge pull request #645 from TheRestartProject/dependabot/npm_and_yar…
edwh May 22, 2023
701d6a6
Merge pull request #643 from TheRestartProject/dependabot/composer/ny…
edwh May 22, 2023
73c0f38
Merge pull request #641 from TheRestartProject/dependabot/composer/gu…
edwh May 22, 2023
f2cca6d
Merge pull request #627 from TheRestartProject/dependabot/npm_and_yar…
edwh May 22, 2023
7e6c694
Merge pull request #648 from TheRestartProject/RES-1890_updated_at_in…
edwh May 22, 2023
469204f
Merge pull request #650 from TheRestartProject/RES-1883_remove_useful…
edwh May 22, 2023
b8d8e79
Allow country names to be translated.
edwh May 22, 2023
1d4da69
Merge pull request #653 from TheRestartProject/RES-1882_sentry
edwh May 22, 2023
40b6397
Test fixes.
edwh May 22, 2023
56920be
Bump socket.io-parser from 4.2.1 to 4.2.3
dependabot[bot] May 24, 2023
4a6b26b
Merge pull request #620 from TheRestartProject/RES-1787_category_sugg…
edwh May 24, 2023
aedb3d7
Merge pull request #656 from TheRestartProject/dependabot/npm_and_yar…
edwh May 24, 2023
97e1d5f
Merge branch 'develop'
edwh May 24, 2023
8f97825
Change "New Zealand" to "Aotearoa New Zealand"
edwh Jun 1, 2023
aafcd39
Improve query efficiency to remove Sentry errors.
edwh Jun 1, 2023
3601677
Test fixes
edwh Jun 1, 2023
41d315e
Caching speedups
edwh Jun 1, 2023
90468a3
Test fixes.
edwh Jun 1, 2023
29c9730
Fix rare test failure.
edwh Jun 1, 2023
beb9a9c
Ignore Sentry errors about Mailgun because we use queue retrying.
edwh Jun 1, 2023
b5d358a
Bit of code coverage.
edwh Jun 1, 2023
1b9260d
Coverage for group tags.
edwh Jun 1, 2023
282c268
Remove warning about group attendance.
edwh Jun 1, 2023
7cfdfa2
Remove dead code, test and fix unapproved groups list.
edwh Jun 1, 2023
225b299
Test fixes.
edwh Jun 1, 2023
b3a30d9
Demote network coordinator.
edwh Jun 5, 2023
6c845be
Demote network coordinator.
edwh Jun 5, 2023
33e8166
Test fixes.
edwh Jun 5, 2023
e276705
Test change to help debug intermittent test failure.
edwh Jun 5, 2023
e10f25c
Change placeholder for brand/model to encourage leaving it blank if n…
edwh Jun 5, 2023
02541da
Fix case sensitivity.
edwh Jun 5, 2023
7cfbb78
Review feedback.
edwh Jun 5, 2023
c302aed
Allow HTML in short Network descriptions.
edwh Jun 5, 2023
4115c39
Translate country in events list.
edwh Jun 5, 2023
0146642
Event approval message showing after it's approved.
edwh Jun 5, 2023
aec2769
Merge pull request #655 from TheRestartProject/RES-1894_translate_cou…
edwh Jun 7, 2023
edd36c4
Duplicate event fixes.
edwh Jun 7, 2023
b678686
Review comment.
edwh Jun 7, 2023
a2503d8
Merge branch 'RES-1894_translate_country_names' into RES-1896_transla…
edwh Jun 7, 2023
3eefce6
Merge.
edwh Jun 7, 2023
942835d
Sort countries by name in registration.
edwh Jun 7, 2023
aced11d
Migrate NZ country names.
edwh Jun 7, 2023
a88a471
Test change to help debug intermittent test failure.
edwh Jun 5, 2023
6234dc0
Test change to diagnose intermittent test failure.
edwh Jun 7, 2023
dcaa389
Test change to diagnose intermittent test failure.
edwh Jun 7, 2023
d78d122
Need to map Belgium too.
edwh Jun 7, 2023
f1ca3da
Back out need to map Belgium too.
edwh Jun 7, 2023
1968013
WIP Add varying message, handle weight mandatory.
edwh Jun 12, 2023
abc1165
Merge branch 'develop' into RES-1896_translate_New_Zealand
edwh Jun 12, 2023
9592197
Merge pull request #658 from TheRestartProject/RES-1896_translate_New…
edwh Jun 12, 2023
4082691
Merge pull request #660 from TheRestartProject/RES-1788_remove_attend…
edwh Jun 12, 2023
69dc878
Add varying message, handle weight mandatory.
edwh Jun 12, 2023
77120b0
Review feedback.
edwh Jun 12, 2023
5730fad
Merge branch 'develop' into RES-1897_sentry
edwh Jun 12, 2023
156b222
Merge pull request #659 from TheRestartProject/RES-1897_sentry
edwh Jun 12, 2023
01afde0
Merge pull request #663 from TheRestartProject/RES-1898_add_Cambridge…
edwh Jun 12, 2023
b709e9a
Merge branch 'develop' into RES-1885_vue_event_create_edit
edwh Jun 12, 2023
fff66cf
Review feedback.
edwh Jun 12, 2023
9aab875
Merge pull request #661 from TheRestartProject/RES-1906_remove_networ…
edwh Jun 12, 2023
9e644b2
Change from storing country names in the DB to country codes.
edwh Jun 12, 2023
2bfb55e
Test fixes.
edwh Jun 21, 2023
3242a38
Fix branch name display.
edwh Jun 21, 2023
e0f4873
Add sync of country code to country field.
edwh Jun 21, 2023
ac3b26c
Test tweaks.
edwh Jun 21, 2023
bd54402
Approve message wrong way round.
edwh Jun 21, 2023
a68e885
Testing feedback.
edwh Jun 27, 2023
a0fa22a
Testing feedback.
edwh Jun 27, 2023
2a17523
Remove old controller code for creating/editing events.
edwh Jun 27, 2023
7f9677c
Test fixes.
edwh Jun 27, 2023
94c00d9
Testing feedback - make weight optional.
edwh Jun 27, 2023
5a87217
Testing feedback - make weight optional.
edwh Jun 27, 2023
c8fe687
Playwright fixes.
edwh Jun 27, 2023
28b2e66
Remove time volunteered / volunteer hours page.
edwh Jul 3, 2023
0ce9671
Merge pull request #667 from TheRestartProject/RES-1912_remove_time_v…
edwh Jul 10, 2023
c36e953
Merge branch 'develop' into RES-1908_country_codes
edwh Jul 10, 2023
e3e7db1
Review fixes
edwh Jul 10, 2023
7e82537
Group table filter bugs.
edwh Jul 10, 2023
84b2b5f
Merge branch 'develop' into RES-1902_unknown_brand
edwh Jul 10, 2023
cfb3129
Add full list.
edwh Jul 10, 2023
849e3b0
Merge branch 'RES-1913_groups_filters_not_working' into RES-1902_unkn…
edwh Jul 10, 2023
fcd911b
Add full list.
edwh Jul 10, 2023
c6204f9
Merge pull request #664 from TheRestartProject/RES-1900_weight_text
edwh Jul 17, 2023
e701f74
Escape group keyword
ngm Aug 1, 2023
b81db47
Use country name matching results from geocoder
ngm Aug 1, 2023
da7c5a4
Merge branch 'develop' into RES-1913_groups_filters_not_working
edwh Aug 2, 2023
fd9e597
Merge pull request #669 from TheRestartProject/RES-1913_groups_filter…
edwh Aug 2, 2023
1abc978
Merge pull request #665 from TheRestartProject/RES-1908_country_codes
edwh Aug 2, 2023
88a79e3
Merge branch 'develop' into RES-1885_vue_event_create_edit
edwh Aug 2, 2023
5f48db1
Merge branch 'develop' into RES-1902_unknown_brand
edwh Aug 2, 2023
eef963f
Merge pull request #662 from TheRestartProject/RES-1902_unknown_brand
edwh Aug 2, 2023
324dbaf
Merge pull request #647 from TheRestartProject/RES-1885_vue_event_cre…
edwh Aug 2, 2023
4de933d
Merge remote-tracking branch 'origin/RES-1858_mapbox_geocode' into RE…
edwh Aug 7, 2023
29f55c4
Merge with develop.
edwh Aug 7, 2023
6e66f03
Grab docker changes for testing in this branch.
edwh Aug 7, 2023
cf19f6b
UT fixes.
edwh Aug 7, 2023
f4f7f0c
Build fixes.
edwh Aug 7, 2023
18af27c
Build fixes.
edwh Aug 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ jobs:
- POSTGRESQL_CLIENT_POSTGRES_USER=postgres
- POSTGRESQL_CLIENT_CREATE_DATABASE_NAME=bitnami_discourse
- POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS=hstore,pg_trgm
- DISCOURSE_EXTRA_CONF_CONTENT=personal_message_enabled_groups \= 10
# networks:
# - app-network

Expand Down Expand Up @@ -139,8 +140,7 @@ jobs:
# Need access to timezones.
- run: mysql --host="127.0.0.1" -u root -ps3cr3t -e "GRANT SELECT ON mysql.time_zone_name TO 'restarters'@'%';"

# We have Discourse on CircleCI. Create Discourse API key. We do this hackily in the DB because the Bitnami image
# doesn't expose an easy way to do it.
# We have Discourse on CircleCI. The API key is inserted using psql below.
- run: sed -i 's/FEATURE__DISCOURSE_INTEGRATION=.*$/FEATURE__DISCOURSE_INTEGRATION=true/g' .env
- run: sed -i 's/DISCOURSE_URL=.*$/DISCOURSE_URL=http:\/\/restarters_discourse/g' .env
- run: sed -i 's/DISCOURSE_APIKEY=.*$/DISCOURSE_APIKEY=fb71f38ca2b8b7cd6a041e57fd8202c9937088f0ecae7db40722bd758dda92fc/g' .env
Expand Down Expand Up @@ -183,7 +183,10 @@ jobs:

# Wait for Discourse to finish initialising.
- run: while ! nc -z restarters_discourse 80; do sleep 1 ; done

# Add the config we need.
- run: psql -h postgresql -U postgres -c "INSERT INTO api_keys (id, user_id, created_by_id, created_at, updated_at, allowed_ips, hidden, last_used_at, revoked_at, description, key_hash, truncated_key) VALUES (1, NULL, 1, '2021-10-25 13:56:20.033338', '2021-10-25 13:56:20.033338', NULL, false, NULL, NULL, 'Restarters', 'd89e9dfacfb611fbaf004807648187ce7ed474df44dcb0ada230fab5c8dd6a5b', '9fd7');" bitnami_discourse
- run: php artisan discourse:setting personal_message_enabled_groups 10

# Run phpunit. Discourse makes things slow, so up the timeout.
- run:
Expand Down
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /var/www
# Install dependencies
RUN sudo apt-get update && \
sudo apt install dnsutils openssl zip unzip git libxml2-dev libzip-dev zlib1g-dev libcurl4-openssl-dev iputils-ping default-mysql-client vim libpng-dev libgmp-dev libjpeg-turbo8-dev && \
sudo apt install php8.1-xmlrpc php8.1-intl php8.1-xdebug php8.1-xmlrpc php8.1-mbstring php8.1-simplexml php8.1-curl php8.1-zip python postgresql-client
sudo apt install php8.1-xmlrpc php8.1-intl php8.1-xdebug php8.1-xmlrpc php8.1-mbstring php8.1-simplexml php8.1-curl php8.1-zip python2 postgresql-client procps telnet vim openssh-server php-xmlrpc

# Clear cache - reduces image size.
RUN sudo apt-get clean && sudo rm -rf /var/lib/apt/lists/*
Expand All @@ -28,8 +28,6 @@ RUN wget https://getcomposer.org/composer-1.phar
EXPOSE 9000

# Install sshd
RUN sudo apt-get update
RUN sudo apt-get install vim openssh-server
RUN sudo sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
RUN sudo mkdir /var/run/sshd
RUN sudo bash -c 'install -m755 <(printf "#!/bin/sh\nexit 0") /usr/sbin/policy-rc.d'
Expand All @@ -39,9 +37,8 @@ RUN sudo RUNLEVEL=1 dpkg-reconfigure openssh-server
RUN sudo ssh-keygen -A -v
RUN sudo update-rc.d ssh defaults

RUN sudo apt-get install python2
RUN sudo pecl install channel://pecl.php.net/xmlrpc-1.0.0RC3 xmlrpc

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

CMD ["bash", "docker_run.sh"]
2 changes: 1 addition & 1 deletion app/Console/Commands/CheckGroupLocations.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CheckGroupLocations extends Command
*
* @var string
*/
protected $description = 'Check that all gtroup locations are geocodeable';
protected $description = 'Check that all group locations are geocodeable';

/**
* Create a new command instance.
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Commands/CheckTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function handle()
// This is probably a special case used for form validation. It throws up many errors, and these
// are at best not visible and at worst not too bad given that they only occur in error cases. So
// ignore it.
} else if ($file == 'countries.php') {
// This is a special case used for country names.
} else if ($file == 'pagination.php') {
// This is probably a special case used for paging through data.
} else if (strpos($file, '-audits')) {
Expand Down
69 changes: 69 additions & 0 deletions app/Console/Commands/DiscourseChangeSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace App\Console\Commands;

use App\Group;
use App\Helpers\Geocoder;
use App\Services\DiscourseService;
use Illuminate\Console\Command;

class DiscourseChangeSetting extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'discourse:setting {setting} {value}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Change Discourse setting';

private $discourseApiKey;
private $discourseApiUser;
private $discourseService;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct(DiscourseService $discourseService)
{
parent::__construct();
$this->discourseService = $discourseService;

$discourseApiKey = env('DISCOURSE_APIKEY');
$discourseApiUser = env('DISCOURSE_APIUSER');

if (is_null($discourseApiKey) || empty($discourseApiKey)) {
$this->error('DISCOURSE_APIKEY is not set');
exit();
}

if (is_null($discourseApiUser) || empty($discourseApiUser)) {
$this->error('DISCOURSE_APIUSER is not set');
exit();
}

$this->discourseApiKey = $discourseApiKey;
$this->discourseApiUser = $discourseApiUser;
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle(DiscourseService $discourseService)
{
$setting = $this->argument('setting');
$value = $this->argument('value');

$this->discourseService->setSetting($setting, $value);
}
}
45 changes: 0 additions & 45 deletions app/Console/Commands/FixLatitudeLongitude.php

This file was deleted.

39 changes: 39 additions & 0 deletions app/Console/Commands/GroupCountryField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Console\Commands;

use App\Group;
use App\Helpers\Fixometer;
use Illuminate\Console\Command;

class GroupCountryField extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'groups:country';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Set the group country field from the country_code field';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$groups = Group::all();

foreach ($groups as $group) {
$group->country = Fixometer::getCountryFromCountryCode($group->country_code);
$group->save();
}
}
}
4 changes: 2 additions & 2 deletions app/Console/Commands/ImportGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function handle()
return iconv( "iso-8859-15", "UTF-8", $str );
}, $fields);

// Format is 'Name', 'Location', 'Postcode', 'Area', 'Country', 'Latitude', 'Longitude', 'Website', 'Phone', 'Networks', 'Description'.
// Format is 'Name', 'Location', 'Postcode', 'Area', 'CountryCode', 'Latitude', 'Longitude', 'Website', 'Phone', 'Networks', 'Description'.

$groupname = $fields[0];
$location = $fields[1];
Expand Down Expand Up @@ -122,7 +122,7 @@ public function handle()
$group->area = $area;
$group->latitude = $lat;
$group->longitude = $lng;
$group->country = $country;
$group->country_code = $country;
$group->website = $website;
$group->phone = $phone;
$group->free_text = $description;
Expand Down
4 changes: 2 additions & 2 deletions app/Console/Commands/SyncDiscourseUsernames.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public function handle()
foreach ($usersFromDiscourse as $discourseUser) {
if (property_exists($discourseUser, 'single_sign_on_record') &&
$discourseUser->single_sign_on_record &&
property_exists($discourseUser->single_sign_on_record, 'external_email')) {
$user = User::where('email', $discourseUser->single_sign_on_record->external_email)->first();
property_exists($discourseUser->single_sign_on_record, 'external_id')) {
$user = User::find($discourseUser->single_sign_on_record->external_id);

if (! is_null($user)) {
$usersFoundInRestarters++;
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Commands/SyncEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use App\Group;
use App\Helpers\Fixometer;
use App\Party;
use DateTime;
use Illuminate\Console\Command;
Expand Down Expand Up @@ -77,7 +78,7 @@ public function handle()

$custom_fields = [
['key' => 'party_grouphash', 'value' => $event->group],
['key' => 'party_groupcountry', 'value' => $group->country],
['key' => 'party_groupcountry', 'value' => Fixometer::getCountryFromCountryCode($group->country_code)],
['key' => 'party_groupcity', 'value' => $group->area],
['key' => 'party_venue', 'value' => $event->venue],
['key' => 'party_location', 'value' => $event->location],
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Commands/SyncGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use App\Group;
use App\Helpers\Fixometer;
use Illuminate\Console\Command;

class SyncGroups extends Command
Expand Down Expand Up @@ -54,7 +55,7 @@ public function handle()
try {
$custom_fields = [
['key' => 'group_city', 'value' => $group->area],
['key' => 'group_country', 'value' => $group->country],
['key' => 'group_country', 'value' => Fixometer::getCountryFromCountryCode($group->country_code)],
['key' => 'group_website', 'value' => $group->website],
['key' => 'group_hash', 'value' => $group->idgroups],
['key' => 'group_latitude', 'value' => $group->latitude],
Expand Down
1 change: 1 addition & 0 deletions app/Console/Commands/UserCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function handle(DiscourseService $discourseService)
$this->info("User created #" . $user->id);

if (config('restarters.features.discourse_integration')) {
$user->generateAndSetUsername();
$discourseService->syncSso($user);
}
} else
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ protected function schedule(Schedule $schedule)
->daily()
->sendOutputTo(storage_path().'/logs/discourse_usernames.log')
->emailOutputTo(env('SEND_COMMAND_LOGS_TO'), 'tech@therestartproject.org');

$schedule->command('groups:country')->hourly();
}

/**
Expand Down
39 changes: 27 additions & 12 deletions app/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static function boot()

static::deleting(function ($device) {
$device->barriers()->detach();
$device->urls()->delete();
});
}

Expand Down Expand Up @@ -216,11 +215,6 @@ public function deviceEvent()
return $this->hasOne(\App\Party::class, 'idevents', 'event');
}

public function urls()
{
return $this->hasMany(\App\DeviceUrl::class, 'device_id', 'iddevices');
}

public function barriers()
{
return $this->belongsToMany(\App\Barrier::class, 'devices_barriers', 'device_id', 'barrier_id');
Expand All @@ -234,10 +228,12 @@ public function eCo2Diverted($emissionRatio, $displacementFactor)
$footprint = 0;

if ($this->isFixed()) {
if ($this->deviceCategory->isMiscPowered() && $this->estimate > 0) {
if ($this->category == env('MISC_CATEGORY_ID_POWERED') && $this->estimate > 0) {
$footprint = $this->estimate * $emissionRatio;
} else {
$footprint = $this->deviceCategory->footprint;
$footprint = \Cache::remember('category-' . $this->category, 15, function() {
return $this->deviceCategory;
})->footprint;
}
}

Expand Down Expand Up @@ -271,11 +267,19 @@ public function eWasteDiverted()
{
$ewasteDiverted = 0;

if ($this->isFixed() && $this->deviceCategory->isPowered()) {
if ($this->deviceCategory->isMiscPowered() && $this->estimate > 0) {
$powered = \Cache::remember('category-powered-' . $this->category, 15, function() {
return $this->deviceCategory->powered;
});

if ($this->isFixed() && $powered) {
if ($this->category == env('MISC_CATEGORY_ID_POWERED') && $this->estimate > 0) {
$ewasteDiverted = $this->estimate;
} else {
$ewasteDiverted = $this->deviceCategory->weight;
$category = \Cache::remember('category-' . $this->category, 15, function() {
return $this->deviceCategory;
});

$ewasteDiverted = $category->weight;
}
}

Expand Down Expand Up @@ -407,7 +411,18 @@ public function poweredCount()
public static function getItemTypes()
{
// List the item types
$types = DB::table('devices')->whereNotNull('item_type')->select('item_type', DB::raw('COUNT(*) as count'))->groupBy('item_type')->orderBy('count', 'desc')->get()->toArray();
$types = DB::select(DB::raw("SELECT s.* FROM
(SELECT item_type, powered, idcategories, categories.name as categoryname, COUNT(*) AS count
FROM devices INNER JOIN categories ON devices.category = categories.idcategories
WHERE item_type IS NOT NULL GROUP BY item_type, categoryname
) s
JOIN
(SELECT item_type, MAX(count) AS maxcount FROM
(SELECT item_type, powered, idcategories, categories.name as categoryname, COUNT(*) AS count
FROM devices INNER JOIN categories ON devices.category = categories.idcategories
WHERE item_type IS NOT NULL GROUP BY item_type, categoryname) s
GROUP BY s.item_type) AS m
ON s.item_type = m.item_type AND s.count = m.maxcount;"));

return $types;
}
Expand Down
Loading