Skip to content

Commit 267f299

Browse files
committed
Add Portal Migration
1 parent 985f1e7 commit 267f299

File tree

8 files changed

+204
-2
lines changed

8 files changed

+204
-2
lines changed

api.php

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,4 +1494,160 @@ function accessDenied()
14941494
]);
14951495
});
14961496

1497+
// Migrate to VANet Portal
1498+
Router::add('/portal_migrate', function () {
1499+
global $user;
1500+
if (!$user->hasPermission('site') || !$user->hasPermission('staffmanage')) accessDenied();
1501+
1502+
$aircraft = array_map(function ($a) {
1503+
return [
1504+
"aircraftLiveryId" => $a->ifliveryid,
1505+
"minimumRankId" => $a->rankreq,
1506+
"requiredAwardId" => $a->awardreq,
1507+
"notes" => $a->notes,
1508+
];
1509+
}, Aircraft::fetchActiveAircraft()->results());
1510+
1511+
$routeAircraft = Route::fetchAllAircraftJoins();
1512+
$routes = array_map(function ($a) use (&$routeAircraft) {
1513+
return [
1514+
"id" => $a["id"],
1515+
"flightNumber" => $a["fltnum"],
1516+
"departureAirportIcao" => $a["dep"],
1517+
"arrivalAirportIcao" => $a["arr"],
1518+
"estimatedFlightTime" => $a["duration"],
1519+
"notes" => $a["notes"],
1520+
"aircraftLiveryIds" => array_map(function ($x) {
1521+
return $x->aircraftliveryid;
1522+
}, array_values(array_filter($routeAircraft, function ($x) use ($a) {
1523+
return $x->routeid == $a["id"];
1524+
}))),
1525+
];
1526+
}, Route::fetchAll());
1527+
1528+
$awardRecipients = Awards::getAllRecipients();
1529+
$awards = array_map(function ($a) use (&$awardRecipients) {
1530+
return [
1531+
"id" => $a->id,
1532+
"name" => $a->name,
1533+
"description" => $a->description,
1534+
"imageUrl" => $a->imageurl,
1535+
"userIds" => array_map(function ($x) {
1536+
return $x->pilotid;
1537+
}, array_values(array_filter($awardRecipients, function ($x) use ($a) {
1538+
return $x->awardid == $a->id;
1539+
})))
1540+
];
1541+
}, Awards::getAll());
1542+
1543+
$allaircraft = Aircraft::fetchAllAircraft();
1544+
$allcomments = Pirep::getAllComments();
1545+
$flights = array_map(function ($f) use ($allaircraft, $allcomments) {
1546+
$aircraftData = array_values(array_filter($allaircraft, function ($x) use ($f) {
1547+
return $x->id == $f["aircraftid"];
1548+
}));
1549+
return [
1550+
"departureIcao" => $f["departure"],
1551+
"arrivalIcao" => $f["arrival"],
1552+
"flightNumber" => $f["flightnum"],
1553+
"date" => $f["date"],
1554+
"fuelUsed" => $f["fuelused"],
1555+
"flightTime" => $f["flighttime"],
1556+
"aircraftLiveryId" => $aircraftData[0]->ifliveryid,
1557+
"multiplierCode" => null,
1558+
"status" => $f["status"],
1559+
"pilotId" => $f["pilotid"],
1560+
"comments" => array_map(function ($y) {
1561+
return [
1562+
"userId" => $y->userid,
1563+
"content" => $y->content,
1564+
"dateTime" => date_format(date_create($y->dateposted), "c"),
1565+
];
1566+
}, array_values(array_filter($allcomments, function ($y) use ($f) {
1567+
return $y->pirepid == $f["id"];
1568+
})))
1569+
];
1570+
}, Pirep::fetchAll());
1571+
1572+
$multipliers = array_map(function ($m) {
1573+
return [
1574+
"code" => strval($m->code),
1575+
"multiplicationFactor" => $m->multiplier,
1576+
"name" => $m->name,
1577+
"expiresAt" => null,
1578+
];
1579+
}, Pirep::fetchMultipliers());
1580+
1581+
$ranks = array_map(function ($r) {
1582+
return [
1583+
"id" => $r->id,
1584+
"name" => $r->name,
1585+
"minFlightTime" => $r->timereq,
1586+
];
1587+
}, Rank::fetchAllNames()->results());
1588+
1589+
$leaves = [];
1590+
if (class_exists('ActivityPlugin')) {
1591+
$leaves = array_map(function ($l) {
1592+
return [
1593+
"startDate" => $l->fromdate,
1594+
"endDate" => $l->todate,
1595+
"reason" => $l->reason,
1596+
"userId" => $l->pilot,
1597+
];
1598+
}, ActivityPlugin::currentFutureLeave());
1599+
}
1600+
1601+
$allpermissions = Permissions::getAllEntries();
1602+
$members = array_map(function ($u) use ($allpermissions) {
1603+
return [
1604+
"id" => $u->id,
1605+
"email" => $u->email,
1606+
"callsign" => $u->callsign,
1607+
"userId" => $u->ifuserid,
1608+
"transferHours" => $u->transhours,
1609+
"transferFlights" => $u->transflights,
1610+
"permissions" => array_map(function ($p) {
1611+
return $p->name;
1612+
}, array_values(array_filter($allpermissions, function ($p) use ($u) {
1613+
return $p->userid == $u->id;
1614+
}))),
1615+
];
1616+
}, User::getActiveUsers());
1617+
1618+
$data = Json::encode([
1619+
"aircraft" => $aircraft,
1620+
"routes" => $routes,
1621+
"awards" => $awards,
1622+
"flights" => $flights,
1623+
"multipliers" => $multipliers,
1624+
"ranks" => $ranks,
1625+
"leaveOfAbsences" => $leaves,
1626+
"members" => $members,
1627+
]);
1628+
$gzdata = gzencode($data, 9);
1629+
1630+
$myinfo = VANet::myInfo();
1631+
$response = HttpRequest::hacky(VANet::baseUrl() . "/airline/v2/" . urlencode($myinfo["id"]) . "/flare-import", "POST", $gzdata, [
1632+
"X-Api-Key: " . Config::get('vanet/api_key'),
1633+
"Content-Type: application/json",
1634+
"Content-Encoding: gzip",
1635+
]);
1636+
$resData = Json::decode($response);
1637+
if ($resData === null) {
1638+
internalError();
1639+
}
1640+
1641+
var_dump($resData);
1642+
1643+
if ($resData["success"]) {
1644+
echo Json::encode([
1645+
'status' => ErrorCode::NoError,
1646+
'result' => null,
1647+
]);
1648+
} else {
1649+
internalError();
1650+
}
1651+
});
1652+
14971653
Router::run('/api.php');

classes/data/Aircraft.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static function findAircraft($liveryId)
105105
}
106106

107107
/**
108-
* @return DB
108+
* @return array
109109
*/
110110
public static function fetchAllAircraft()
111111
{

classes/data/Awards.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ public static function getAll()
3030
return $q->results();
3131
}
3232

33+
public static function getAllRecipients()
34+
{
35+
self::init();
36+
$q = self::$_db->getAll('awards_granted');
37+
if ($q->error()) {
38+
throw new Exception("Failed to fetch award recipients");
39+
}
40+
41+
return $q->results();
42+
}
43+
3344
public static function get($id)
3445
{
3546
self::init();

classes/data/Permissions.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,14 @@ public static function usersWith($perm)
130130
$sql = "SELECT u.* FROM pilots u WHERE u.id IN (SELECT p.userid FROM permissions p WHERE name=?)";
131131
return self::$_db->query($sql, [$perm])->results();
132132
}
133+
134+
/**
135+
* @return array
136+
*/
137+
public static function getAllEntries()
138+
{
139+
self::init();
140+
141+
return self::$_db->getAll('permissions')->results();
142+
}
133143
}

classes/data/Pirep.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ public static function getComments($pirepid)
312312
return $q->results();
313313
}
314314

315+
316+
/**
317+
* @return array|null
318+
* @param int $pirepid PIREP ID
319+
*/
320+
public static function getAllComments()
321+
{
322+
self::init();
323+
$q = self::$_db->getAll('pireps_comments');
324+
if ($q->error()) return null;
325+
326+
return $q->results();
327+
}
328+
315329
/**
316330
* @return array|null
317331
* @param int $id Comment ID

classes/data/User.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,15 @@ public function getAllUsers()
466466
return $usersarray;
467467
}
468468

469+
/**
470+
* @return array
471+
*/
472+
public static function getActiveUsers()
473+
{
474+
$db = DB::newInstance();
475+
return $db->get('pilots', ['status', '=', 1])->results();
476+
}
477+
469478
/**
470479
* @return array
471480
*/

docker-compose.override.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ services:
2626
environment:
2727
PMA_HOST: db
2828
ports:
29-
- 8080:80
29+
- 8090:80
3030
depends_on:
3131
- db

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ services:
4141
networks:
4242
flare:
4343
driver: bridge
44+
hostt:
45+
driver: host
4446

4547
volumes:
4648
flare-mysql:

0 commit comments

Comments
 (0)