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-1911 Some issues with item type suggestions #670

Merged
merged 7 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ jobs:

- run: wget https://getcomposer.org/composer-2.phar -O composer.phar; rm -rf vendor; echo Y | php8.1 composer.phar install
- run: npm install
- run: php artisan lang:js --no-lib resources/js/translations.js
- run: npx playwright install
- run: npx playwright install-deps
- run: npm install -D @playwright/test
Expand Down Expand Up @@ -196,6 +197,9 @@ jobs:
# Coveralls is pernickety about the location it uploads from existing.
- run: mkdir build; mkdir build/logs; php vendor/bin/php-coveralls -v -x tests/clover.xml

# Run the Jest tests.
- run: npm run jest

# Run the Playwright tests.
#
# Zap groups set up by the UT; this can confuse Playwright tests.
Expand Down
68 changes: 1 addition & 67 deletions .circleci/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,87 +1,21 @@
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /home/circleci/project/public;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;

server_name _;

try_files $uri /index.php;

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
}
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"]
55 changes: 42 additions & 13 deletions app/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,19 +410,48 @@ public function poweredCount()

public static function getItemTypes()
{
// List the item types
$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;"));
// List the item types.
//
// This is a beast of a query, but the basic idea is to return a list of the categories most commonly
// used by the item types.
//
// ANY_VALUE is used to suppress errors when SQL mode is not set to ONLY_FULL_GROUP_BY.
$types = DB::select(DB::raw("
SELECT item_type,
ANY_VALUE(powered) AS powered,
ANY_VALUE(idcategories) AS idcategories,
ANY_VALUE(categoryname)
FROM (SELECT DISTINCT s.*
FROM (SELECT item_type,
ANY_VALUE(powered) AS powered,
ANY_VALUE(idcategories) AS 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 categoryname,
item_type) s
JOIN (SELECT item_type,
MAX(count) AS maxcount
FROM (SELECT item_type AS item_type,
ANY_VALUE(powered) AS powered,
ANY_VALUE(idcategories) AS 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 categoryname,
item_type) s
GROUP BY s.item_type) AS m
ON s.item_type = m.item_type
AND s.count = m.maxcount) t
GROUP BY t.item_type
"));

return $types;
}
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {presets: ['@babel/preset-env']}
28 changes: 28 additions & 0 deletions database/migrations/2023_08_02_183803_item_type_collation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::statement(DB::raw("ALTER TABLE `devices` CHANGE `item_type` `item_type` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL;"));
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::statement(DB::raw("ALTER TABLE `devices` CHANGE `item_type` `item_type` VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL;"));
}
};
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ services:
volumes:
# We share the current folder into /var/www. This means code changes on the host will get picked up
# by the client.
- ./:/var/www
- ./:/var/www:rw
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
Expand Down
7 changes: 6 additions & 1 deletion docker_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# We install composer dependencies in here rather than during the build step so that if we switch branches
# and restart the container, it works.
service ssh start

if [ ! -f .env ]
then
cp .env.example .env
Expand All @@ -28,17 +30,20 @@ sed -i 's/DISCOURSE_SECRET=.*$/DISCOURSE_SECRET=mustbetencharacters/g' .env
sed -i 's/SESSION_DOMAIN=.*$/SESSION_DOMAIN=/g' phpunit.xml
sed -i 's/DB_TEST_HOST=.*$/DB_TEST_HOST=restarters_db/g' phpunit.xml

mkdir storage/framework/cache/data
php artisan migrate
npm install --legacy-peer-deps
npm rebuild node-sass
php artisan lang:js --no-lib resources/js/translations.js
chmod -R 777 public

npm run watch&
php artisan key:generate
php artisan cache:clear
php artisan config:clear

# Ensure we have the admin user
echo "User::create(['name'=>'Jane Bloggs','email'=>'jane@bloggs.net','password'=>Hash::make('passw0rd'),'role'=>2]);" | php artisan tinker
echo "User::create(['name'=>'Jane Bloggs','email'=>'jane@bloggs.net','password'=>Hash::make('passw0rd'),'role'=>2,'consent_past_data'=>'2021-01-01','consent_future_data'=>'2021-01-01','consent_gdpr'=>'2021-01-01']);" | php artisan tinker

php artisan serve --host=0.0.0.0 --port=80

Expand Down
24 changes: 24 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
// "collectCoverage": true,
// "collectCoverageFrom": ["**/resources/js/components/*.{js,vue}", "!**/node_modules/**"]
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
".*\\.(vue)$": "@vue/vue2-jest",
"^.+\\.(js|jsx)$": "babel-jest"
},
"roots": [
"<rootDir>/resources/js/components"
],
"modulePaths": [
"<rootDir>"
],
"moduleDirectories": [
"node_modules"
],
"setupFilesAfterEnv": ["<rootDir>/tests/jest.setup.js"],
"testEnvironment": "jsdom"
}
Loading