Skip to content
Closed
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- The staff "New reply from client" email shows the client's reply.
- **Language versions of the texts clients see:** invoice notes, company signature and legal texts, the email signature, store title, maintenance message, bank transfer instructions, suspension and cancellation reasons, and escalation replies.
- **Import Products step:** before an import from Upmind, Blesta, Clientexec, Paymenter or FOSSBilling, choose for each source product whether it stays custom or becomes a hosting product on a chosen server and plan.
- **Orders > Move services:** move the services of one product to another product in bulk.
- **Orders > Move services:** move the services of one product to another product in bulk. An explicit override moves custom services to hosting without checking or linking the server account; link them later when the server is available.
- **Failed staff sign-in email:** the Super Administrators get an email at once when a staff sign-in fails, as WHMCS.
- The domain checker, contact and sign-in embeds take the client area's look: brand colours, font, buttons and fields, in light and dark mode.
- **Registrars:** Update and Test Connection on the registrar settings page, showing how long the registrar took or its error.
Expand Down
3 changes: 3 additions & 0 deletions src/modules/Order/Api/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ public function move_services_options($data): array
* @optional int $to_product_id - a hosting or custom product (required)
* @optional array $statuses - order statuses (required)
* @optional int $after - list the orders after this order ID
* @optional bool $move_unlinked - move to hosting without checking or linking the server account
*/
public function move_services_preview($data): array
{
Expand All @@ -1020,6 +1021,8 @@ public function move_services_preview($data): array

/**
* ClientFence: moves the previewed services (`order_ids`), each checked again; one result per service.
*
* @optional bool $move_unlinked - move to hosting without checking or linking the server account
*/
#[RequiredParams(['order_ids' => 'Preview the services first'])]
public function move_services($data): array
Expand Down
61 changes: 47 additions & 14 deletions src/modules/Order/ProductMove.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ClientFence\Mod\Product\Entity\Product;
use ClientFence\Mod\Servicehosting\Panel\Enhance\Panel;
use ClientFence\Mod\Servicehosting\Service as HostingService;
use ClientFence\Tools;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Connection;

Expand Down Expand Up @@ -79,6 +80,7 @@ public static function preview(\Pimple\Container $di, array $data): array
{
$db = self::db($di);
[$from, $to] = self::products($db, $data);
$offline = Tools::normalizeBoolean($data['move_unlinked'] ?? false);
$statuses = array_values(array_intersect(self::STATUSES, array_map('strval', (array) ($data['statuses'] ?? []))));
if ($statuses === []) {
throw new InformationException('Choose at least one order status.');
Expand All @@ -94,7 +96,7 @@ public static function preview(\Pimple\Container $di, array $data): array
$domains = self::domains($db, $from['id']);
$rows = [];
foreach (array_slice($orders, 0, self::LIMIT) as $order) {
$found = self::check($di, $order, $from, $to, $domains);
$found = self::check($di, $order, $from, $to, $domains, $offline);
$rows[] = [
'id' => (int) $order['id'],
'title' => (string) $order['title'],
Expand All @@ -121,6 +123,7 @@ public static function move(\Pimple\Container $di, array $data): array
{
$db = self::db($di);
[$from, $to] = self::products($db, $data);
$offline = Tools::normalizeBoolean($data['move_unlinked'] ?? false);
$ids = array_values(array_unique(array_filter(array_map('intval', (array) ($data['order_ids'] ?? [])), static fn (int $id): bool => $id > 0)));
if ($ids === [] || count($ids) > self::LIMIT) {
throw new InformationException('Choose between 1 and :max services to move.', [':max' => self::LIMIT]);
Expand All @@ -133,7 +136,7 @@ public static function move(\Pimple\Container $di, array $data): array
if ($order === false || (int) $order['product_id'] !== $from['id'] || !in_array($order['status'], self::STATUSES, true)) {
throw new InformationException('This service is no longer on :product.', [':product' => $from['title']]);
}
$found = self::check($di, $order, $from, $to, $domains);
$found = self::check($di, $order, $from, $to, $domains, $offline);
if ($found['reason'] !== null) {
$results[] = ['id' => $id, 'moved' => false, 'note' => $found['reason']];

Expand Down Expand Up @@ -163,7 +166,7 @@ public static function move(\Pimple\Container $di, array $data): array
*
* @return array{reason: ?string, domain?: string, link?: array{org: string, subscription: int}, adapter?: object, account?: \Server_Account, server_id?: int, plan_id?: int}
*/
private static function check(\Pimple\Container $di, array $order, array $from, array $to, array $domains): array
private static function check(\Pimple\Container $di, array $order, array $from, array $to, array $domains, bool $offline): array
{
$inPlace = $from['id'] === $to['id'];
if ($inPlace) {
Expand Down Expand Up @@ -210,6 +213,17 @@ private static function check(\Pimple\Container $di, array $order, array $from,
return ['reason' => __trans('Order #:id is already a hosting service for this domain.', [':id' => $taken]), 'domain' => $domain];
}

if ($offline && !$inPlace) {
try {
$di['db']->getExistingModelById('ServiceHostingServer', $serverId, 'Server not found');
$di['db']->getExistingModelById('ServiceHostingHp', $planId, 'Hosting plan not found');
} catch (\ClientFence\Exception $e) {
return ['reason' => $e->getMessage(), 'domain' => $domain];
}

return ['reason' => null, 'domain' => $domain, 'server_id' => $serverId, 'plan_id' => $planId];
}

try {
$model = $di['db']->dispense('ServiceHosting');
$model->client_id = (int) $order['client_id'];
Expand Down Expand Up @@ -262,12 +276,13 @@ private static function check(\Pimple\Container $di, array $order, array $from,
* The order becomes a hosting order of $to whose service is the found account: the hosting module's "already set
* up" activation (Add New Order), so nothing is created on the server. The custom service row goes last.
*
* @param array{domain: string, link: array{org: string, subscription: int}, adapter: object, account: \Server_Account, server_id: int, plan_id: int} $found
* @param array{domain: string, link?: array{org: string, subscription: int}, adapter?: object, account?: \Server_Account, server_id: int, plan_id: int} $found
*/
private static function link(\Pimple\Container $di, int $orderId, array $matched, array $from, array $to, array $found): void
{
$domain = $found['domain'];
$login = self::login($found);
$linked = isset($found['link']);
$login = $linked ? self::login($found) : '';
$hosting = $di['mod_service']('servicehosting');
[$sld, $tld] = self::split($domain);
// Only the hosting keys of the product (as Upgrades::hostingConfig()): the order keeps its own billing settings
Expand All @@ -279,11 +294,14 @@ private static function link(\Pimple\Container $di, int $orderId, array $matched
'tld' => $tld,
'import' => true,
'username' => $login,
'clientfence_move_unlinked' => !$linked,
];
$note = sprintf('Moved by staff from %s to %s, linked to the existing account %s on the server', $from['title'], $to['title'], $domain);
$note = $linked
? sprintf('Moved by staff from %s to %s, linked to the existing account %s on the server', $from['title'], $to['title'], $domain)
: sprintf('Moved by staff from %s to %s without verifying or linking the account %s on the server', $from['title'], $to['title'], $domain);

$db = self::db($di);
$release = self::lock($db, $found['link']);
$release = $linked ? self::lock($db, $found['link']) : static function (): void {};
$db->beginTransaction();
try {
self::recheck($db, $matched, $found, 0);
Expand All @@ -295,14 +313,18 @@ private static function link(\Pimple\Container $di, int $orderId, array $matched
$order->title = mb_substr($hosting->getCartProductTitle($di['em']->find(Product::class, $to['id']), $config) ?? $to['title'], 0, 255);
$order->config = json_encode($config);
$service = $hosting->action_create($order);
$service->panel_org_id = $found['link']['org'];
$service->panel_subscription_id = $found['link']['subscription'];
$di['db']->store($service);
if ($linked) {
$service->panel_org_id = $found['link']['org'];
$service->panel_subscription_id = $found['link']['subscription'];
$di['db']->store($service);
}
$order->service_type = 'hosting';
$order->service_id = $service->id;
$order->updated_at = date('Y-m-d H:i:s');
$di['db']->store($order);
$hosting->action_activate($order);
if ($linked) {
$hosting->action_activate($order);
}
$db->delete('service_custom', ['id' => $customId]);
$di['mod_service']('order')->saveStatusChange($order, $note);
$db->commit();
Expand Down Expand Up @@ -341,6 +363,12 @@ private static function attach(\Pimple\Container $di, int $orderId, array $match
'service_hosting_server_id' => $found['server_id'], 'service_hosting_hp_id' => $found['plan_id'], 'sld' => $sld, 'tld' => $tld,
'updated_at' => date('Y-m-d H:i:s'),
], ['id' => (int) $order->service_id]);
$config = json_decode((string) $order->config, true);
if (is_array($config) && !empty($config['clientfence_move_unlinked'])) {
unset($config['clientfence_move_unlinked']);
$order->config = json_encode($config);
$di['db']->store($order);
}
$di['mod_service']('order')->saveStatusChange($order, $note);
});
} finally {
Expand All @@ -364,9 +392,11 @@ private static function recheck(Connection $db, array $matched, array $found, in
throw new InformationException('This service changed while it was being moved. Preview it again.');
}
}
$linked = $db->fetchOne('SELECT id FROM service_hosting WHERE panel_org_id = ? AND panel_subscription_id = ? AND id <> ?', [$found['link']['org'], $found['link']['subscription'], $serviceId]);
if ($linked !== false) {
throw new InformationException('This account is already linked to hosting service #:id.', [':id' => $linked]);
if (isset($found['link'])) {
$linked = $db->fetchOne('SELECT id FROM service_hosting WHERE panel_org_id = ? AND panel_subscription_id = ? AND id <> ?', [$found['link']['org'], $found['link']['subscription'], $serviceId]);
if ($linked !== false) {
throw new InformationException('This account is already linked to hosting service #:id.', [':id' => $linked]);
}
}
}

Expand Down Expand Up @@ -477,6 +507,9 @@ private static function products(Connection $db, array $data): array
if ($to === null || ($from['type'] === 'hosting') !== ($to['id'] === $from['id'])) {
throw new InformationException('Choose another custom product, or a hosting product with a server and hosting plan, to move the services to. To link the services of a hosting product to their accounts, choose that product in both.');
}
if (Tools::normalizeBoolean($data['move_unlinked'] ?? false) && ($from['type'] !== 'custom' || $to['type'] !== 'hosting')) {
throw new InformationException('The unlinked move option is only for moves from a custom product to a hosting product. Turn it off to link services.');
}

return [$from, $to];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="card-header">
<div>
<h3 class="card-title">{{ 'Move services to another product'|trans }}</h3>
<p class="card-subtitle">{{ "For services that came in under a custom product. Moved to a hosting product, each service is linked to its existing account on the product's server, found by its domain; nothing is created on the server. The order keeps its price, billing period, due date, invoices and status."|trans }}</p>
<p class="card-subtitle">{{ "For services that came in under a custom product. Normally, a move to a hosting product links each service to its existing account on the product's server, found by its domain; nothing is created on the server. The order keeps its price, billing period, due date, invoices and status."|trans }}</p>
</div>
</div>
<div class="card-body">
Expand Down Expand Up @@ -70,6 +70,11 @@
{% endfor %}
</div>
</div>
<label class="form-check mt-3">
<input class="form-check-input" type="checkbox" name="move_unlinked" value="1"{% if filters.move_unlinked|default('') == '1' %} checked{% endif %}>
<span class="form-check-label">{{ 'I understand: move without checking or linking the server account'|trans }}</span>
</label>
<div class="form-hint">{{ 'For moves from a custom product to a hosting product only. The account and login will be unverified; hosting actions and renewals will fail until the services are linked. Once the server is available, turn off this option and choose the hosting product as both source and destination to link them. Local checks still apply.'|trans }}</div>
</div>
<div class="card-footer text-end">
<button class="btn btn-primary" type="submit">{{ 'Preview'|trans }}</button>
Expand Down Expand Up @@ -110,6 +115,7 @@
<td class="small" data-cf-move-result="{{ row.id }}">
{% if row.reason is not null %}{{ row.reason }}
{% elseif row.link %}{{ 'Organization %org%, subscription %id%'|trans({ '%org%': row.link.org, '%id%': row.link.subscription }) }}
{% elseif filters.move_unlinked|default('') == '1' %}{{ 'Moves unlinked; account not verified'|trans }}
{% else %}{{ 'Moves without a server account'|trans }}{% endif %}
</td>
</tr>
Expand All @@ -127,6 +133,7 @@
<form method="post" action="{{ 'order/move_services'|api_url }}" {{ fb_api_form({ callback: 'clientfenceServicesMoved' }) }}>
<input type="hidden" name="from_product_id" value="{{ filters.from_product_id }}">
<input type="hidden" name="to_product_id" value="{{ filters.to_product_id }}">
{% if filters.move_unlinked|default('') == '1' %}<input type="hidden" name="move_unlinked" value="1">{% endif %}
{% for row in movable %}<input type="hidden" name="order_ids[]" value="{{ row.id }}">{% endfor %}
<button class="btn btn-primary" type="submit">{% if filters.from_product_id == filters.to_product_id %}{{ 'Link %count% services'|trans({ '%count%': movable|length }) }}{% else %}{{ 'Move %count% services'|trans({ '%count%': movable|length }) }}{% endif %}</button>
</form>
Expand Down
Loading