Skip to content
Open
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
56 changes: 16 additions & 40 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,27 @@
FROM php:8.5-cli
FROM uspdev/uspdev-php-apache:8.4

RUN sed -i 's|main|main non-free|' /etc/apt/sources.list.d/debian.sources && apt-get update && apt-get install -y \
unixodbc \
unixodbc-dev \
freetds-bin \
freetds-dev \
libicu-dev \
git \
unzip \
libzip-dev \
libpng-dev \
libonig-dev \
libxml2-dev \
libjpeg-dev \
libfreetype6-dev \
libssl-dev \
curl
RUN sed -i 's|/var/www/html|/var/www/html/public|' \
/etc/apache2/sites-available/000-default.conf

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# php libs (Core)
RUN docker-php-ext-install \
intl \
pdo_mysql \
soap \
zip \
mbstring \
bcmath \
pdo_dblib
# bibliotecas para mongo
RUN apt-get update && apt-get install -y \
libssl-dev \
pkg-config

# Driver do MongoDB (Obrigatório para CLI também)
RUN pecl install mongodb && docker-php-ext-enable mongodb

# gd
RUN docker-php-ext-configure gd --with-freetype --with-jpeg && \
docker-php-ext-install gd

# php memory
# php memory
ENV PHP_MEMORY_LIMIT=2048M
RUN echo "memory_limit=${PHP_MEMORY_LIMIT}" > "${PHP_INI_DIR}/conf.d/memory.ini"

# Setup do diretório de trabalho
WORKDIR /app
USER www-data

COPY --chown=www-data . .

COPY . .
RUN composer install
RUN composer install \
--no-dev \
--optimize-autoloader \
--no-interaction

CMD ["tail", "-f", "/dev/null"]
CMD ["apache2-foreground"]
37 changes: 37 additions & 0 deletions bin/make-collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
#Diretórios do esqueleto e de collections
$stubPath = __DIR__ . '/../stubs/collection.stub';
$collectionDir = __DIR__ . '/../src/Collections/';

#Verifica se foi passado um argumento
if (is_null($argv[1])) {
echo "Erro: Você precisa passar o nome da coleção.\n";
echo "Exemplo: php gerar-collection.php Alunos\n";
exit(1);
}

#Verifica se existe um arquivo de esqueleto
if (!file_exists($stubPath)) {
echo "Erro: Arquivo padrão não encontrado.";
exit(1);
}
#Guarda o nome o a primeira letra maiúscula e com todas as letras minúsculas
$name_capitalize = ucfirst($argv[1]);
$name_lower = strtolower($name_capitalize);

#Caminho do arquivo da nova collection
$collectionPath = $collectionDir . $name_lower . 'Collection.php';

#guarda no $content o conteúdo do esqueleto com os nomes trocados
$content = file_get_contents($stubPath);
$content = str_replace('{{ name_capitalize }}', $name_capitalize, $content);
$content = str_replace('{{ name_lower }}', $name_lower, $content);

#coloca o conteúdo final no arquivo collection e verifica se teve sucesso
if(file_put_contents($collectionPath, $content) !== false){
echo "Arquivo criado: $collectionPath\n";
}
else{
echo "Erro ao salvar arquivo.";
}

12 changes: 6 additions & 6 deletions bin/sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
Bootstrap::init();

// Roda uma collection em particular
/*
use Uspdev\Replicado2MongoDB\Collections\programasCollection;
$sync = new programasCollection();

use Uspdev\Replicado2MongoDB\Collections\docentesCollection;
$sync = new docentesCollection();
$sync->sync();
*/


// Roda todas collections
$runner = new SyncRunner();
$runner->run();
/* $runner = new SyncRunner();
$runner->run(); */



7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
services:
replicado2mongodb:
build: .
image: replicado2mongodb
container_name: replicado2mongodb
ports:
- "8000:80"
depends_on:
- mongodb
networks:
- replicado2mongodb-network
volumes:
- ./:/app
- ./:/var/www/html
environment:
HOME: /tmp
user: "${UID:-1000}:${GID:-1000}"
Expand All @@ -25,7 +28,7 @@ services:
- mongodb_data:/data/db
networks:
- replicado2mongodb-network

mongo-express:
image: mongo-express:latest
container_name: replicado2mongodb_mongo_express
Expand Down
11 changes: 11 additions & 0 deletions resources/queries/listarDisciplinasDocentes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT DISTINCT
S.nomset, --AS NomeDepartamento,
V.tipmer, --AS MeritoDocente,
M.codpes, --AS NUSP,
V.nompes, --AS NomeDocente,
M.coddis, --AS Disciplina,
M.codtur --AS Turma
FROM MINISTRANTE M
INNER JOIN VINCULOPESSOAUSP V ON V.codpes = M.codpes
INNER JOIN SETOR S ON S.codset = V.codset
WHERE V.codfusclgund IN (__unidades__)
7 changes: 7 additions & 0 deletions resources/queries/listarDocentes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT DISTINCT
V.codpes, V.nompes, S.nomset, V.codset, S.nomabvset, V.tipmer, V.nomabvcla, V.nomabvfnc, V.sitatl, V.sitoco, V.dtafimvin, V.dtafimdctati
FROM VINCULOPESSOAUSP AS V
INNER JOIN SETOR AS S ON S.codset = V.codset
WHERE V.tipvin = 'SERVIDOR'
AND V.nomcaa = 'Docente'
AND V.codfusclgund IN (__unidades__)
5 changes: 5 additions & 0 deletions resources/queries/listarEstagiarios.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT V.codpes, V.nompes, S.nomset, V.dtainivin, V.dtafimvin
FROM VINCULOPESSOAUSP V
INNER JOIN SETOR S ON V.codset = S.codset
WHERE V.tipvin = 'ESTAGIARIORH'
AND V.codfusclgund IN (__unidades__)
4 changes: 4 additions & 0 deletions resources/queries/listarIntercambistasRecebidos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT DISTINCT V.nompes, V.codpes, V.dtainivin, V.dtafimvin, V.tipvin
FROM VINCULOPESSOAUSP AS V
WHERE V.tipvin IN ('ALUNOICD', 'ALUNOCONVENIOINT')
AND V.codfusclgund IN (__unidades__)
10 changes: 10 additions & 0 deletions resources/queries/listarPosGrad.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT DISTINCT
V.codpes, --AS NUSP,
L.codema, --AS Email,
L.nompes, --AS Nome,
V.codare
FROM VINCULOPESSOAUSP AS V
INNER JOIN LOCALIZAPESSOA as L ON (V.codpes = L.codpes)
WHERE V.tipvin = 'ALUNOPOS'
AND V.sitatl = 'A'
AND V.codfusclgund IN (__unidades__)
59 changes: 59 additions & 0 deletions src/Collections/disciplinasdocentesCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Uspdev\Replicado2MongoDB\Collections;

use Uspdev\Replicado2MongoDB\Contracts\CollectionInterface;

use MongoDB\BSON\UTCDateTime;

use Uspdev\Replicado2MongoDB\Database\MongoConnection;
use Uspdev\Replicado\DB as ReplicadoDB;

class disciplinasdocentesCollection extends Collection implements CollectionInterface
{
public function sync(): void
{
$query = $this->getQuery('listarDisciplinasDocentes.sql',
[
'__unidades__' => env('REPLICADO_CODUNDCLG')
]
);
$disciplinasdocentes = ReplicadoDB::fetchAll($query);
$qtd = count($disciplinasdocentes);

// Pegar dados do replicado
$now = new UTCDateTime();
foreach ($disciplinasdocentes as $registro) {
$bulk[] = [
'updateOne' => [
['nusp_docente' => $registro['codpes'],
'disciplina' => $registro['coddis'],
'turma' => $registro['codtur']
],
[
'$set' => [
'departamento' => $registro['nomset'],
'merito_docente' => $registro['tipmer'],
'nusp_docente' => $registro['codpes'],
'nome_docente' => $registro['nompes'],
'disciplina' => $registro['coddis'],
'turma' => $registro['codtur'],
'updated_at_sync' => $now
]
],
['upsert' => true]
]
];
}

$collection = MongoConnection::getCollection('disciplinasdocentes');
if (!empty($bulk)) {
$collection->bulkWrite($bulk);
}

// delete antigos
$collection->deleteMany([
'updated_at_sync' => ['$lt' => $now]
]);
}
}
62 changes: 62 additions & 0 deletions src/Collections/docentesCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Uspdev\Replicado2MongoDB\Collections;

use Uspdev\Replicado2MongoDB\Contracts\CollectionInterface;

use MongoDB\BSON\UTCDateTime;

use Uspdev\Replicado2MongoDB\Database\MongoConnection;
use Uspdev\Replicado\DB as ReplicadoDB;

class docentesCollection extends Collection implements CollectionInterface
{
public function sync(): void
{
$query = $this->getQuery('listarDocentes.sql',
[
'__unidades__' => env('REPLICADO_CODUNDCLG')
]
);

$docentes = ReplicadoDB::fetchAll($query);

// Pegar dados do replicado
$now = new UTCDateTime();
foreach ($docentes as $registro) {
$bulk[] = [
'updateOne' => [
['codpes' => $registro['codpes']],
[
'$set' => [
'codpes' => $registro['codpes'],
'nome_docente' => $registro['nompes'],
'nome_setor' => $registro['nomset'],
'cod_setor' => $registro['codset'],
'clg_setor' => $registro['nomabvset'],
'merito' => $registro['tipmer'],
'classe' => $registro['nomabvcla'],
'funcao' => $registro['nomabvfnc'],
'status' => $registro['sitatl'],
'ultima_ocorrencia' => $registro['sitoco'],
'fim_vinculo' => explode(' ',$registro['dtafimvin'] ?? '')[0],
'fim_atividade' => explode(' ',$registro['dtafimdctati'] ?? '')[0],
'updated_at_sync' => $now
]
],
['upsert' => true]
]
];
}

$collection = MongoConnection::getCollection('docentes');
if (!empty($bulk)) {
$collection->bulkWrite($bulk);
}

// delete antigos
$collection->deleteMany([
'updated_at_sync' => ['$lt' => $now]
]);
}
}
54 changes: 54 additions & 0 deletions src/Collections/estagiariosCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Uspdev\Replicado2MongoDB\Collections;

use Uspdev\Replicado2MongoDB\Contracts\CollectionInterface;

use MongoDB\BSON\UTCDateTime;

use Uspdev\Replicado2MongoDB\Database\MongoConnection;
use Uspdev\Replicado\DB as ReplicadoDB;

class estagiariosCollection extends Collection implements CollectionInterface
{
public function sync(): void
{
$query = $this->getQuery('listarEstagiarios.sql',
[
'__unidades__' => env('REPLICADO_CODUNDCLG')
]
);
$estagiarios = ReplicadoDB::fetchAll($query);

// Pegar dados do replicado
$now = new UTCDateTime();
foreach ($estagiarios as $registro) {
$bulk[] = [
'updateOne' => [
['codpes' => $registro['codpes']],
[
'$set' => [
'codpes'=> $registro['codpes'],
'nome' => $registro['nompes'],
'setor' => $registro['nomset'],
'inicio'=> explode(' ', $registro['dtainivin'])[0],
'fim' => explode(' ', $registro['dtafimvin'])[0],
'updated_at_sync' => $now
]
],
['upsert' => true]
]
];
}

$collection = MongoConnection::getCollection('estagiarios');
if (!empty($bulk)) {
$collection->bulkWrite($bulk);
}

// delete antigos
$collection->deleteMany([
'updated_at_sync' => ['$lt' => $now]
]);
}
}
Loading