Skip to content
Merged
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
43 changes: 3 additions & 40 deletions src/runtemplateclone.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
namespace MultiFlexi\Ui;

use Ease\WebPage;
use MultiFlexi\Configuration;
use MultiFlexi\RunTemplate;
use MultiFlexi\RunTplCreds;

require_once './init.php';
WebPage::singleton()->onlyForLogged();
Expand All @@ -39,48 +37,13 @@
// Load source runtemplate
$sourceTemplate = new RunTemplate($sourceId);

// Create new runtemplate
$newTemplate = new RunTemplate();

// Copy basic data from source template
$templateData = $sourceTemplate->getData();
unset($templateData[$sourceTemplate->getKeyColumn()]); // Remove ID
$templateData['name'] = $cloneName;
unset($templateData['last_schedule'], $templateData['next_schedule'], $templateData['failed_jobs_count'], $templateData['successfull_jobs_count']);

// Insert new template
$newId = $newTemplate->insertToSQL($templateData);
// Clone always comes back disabled, regardless of the source's state
$newId = $sourceTemplate->cloneAs($cloneName);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚑ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Check Composer declarations and the locked core-package revision.
while IFS= read -r manifest; do
  echo "== ${manifest} =="
  rg -n -C 3 '"vitexsoftware/multiflexi-core"' "${manifest}" || true
done < <(fd -HI -t f '^composer\.(json|lock)$' .)

# Check any available source copy of RunTemplate for cloneAs().
while IFS= read -r file; do
  echo "== ${file} =="
  rg -n -C 3 'function\s+cloneAs\s*\(' "${file}" || true
done < <(fd -HI -t f 'RunTemplate\.php$' .)

Repository: VitexSoftware/multiflexi-web

Length of output: 218


🏁 Script executed:

set -euo pipefail

echo '== Composer manifests =='
git ls-files | grep -E '(^|/)composer\.(json|lock)$' | while IFS= read -r manifest; do
  echo "== $manifest =="
  grep -n -C 4 'vitexsoftware/multiflexi-core' "$manifest" || true
done

echo '== RunTemplate implementations =='
git ls-files | grep -E '(^|/)RunTemplate\.php$' | while IFS= read -r file; do
  echo "== $file =="
  grep -n -C 5 -E 'function[[:space:]]+cloneAs[[:space:]]*\(' "$file" || true
done

echo '== Relevant source context =='
if [ -f src/runtemplateclone.php ]; then
  nl -ba src/runtemplateclone.php | sed -n '1,100p'
fi

Repository: VitexSoftware/multiflexi-web

Length of output: 4277


🏁 Script executed:

set -euo pipefail

python3 - <<'PY'
import json
from pathlib import Path

lock = json.loads(Path("composer.lock").read_text())
for package in lock.get("packages", []) + lock.get("packages-dev", []):
    if package.get("name") == "vitexsoftware/multiflexi-core":
        print(json.dumps(package, indent=2))
PY

echo '== Upstream refs =='
if command -v curl >/dev/null 2>&1; then
  curl -fsSL 'https://api.github.com/repos/VitexSoftware/php-vitexsoftware-multiflexi-core/commits/main' \
    | python3 -c 'import json,sys; d=json.load(sys.stdin); print(d.get("sha","")); print(d.get("html_url",""))'
fi

Repository: VitexSoftware/multiflexi-web

Length of output: 2865


🏁 Script executed:

set -euo pipefail

repo='VitexSoftware/php-vitexsoftware-multiflexi-core'
sha='80eefa9362998179c5f68374ec5dc77fd605cc57'

for path in \
  'src/MultiFlexi/RunTemplate.php' \
  'src/MultiFlexi/RunTemplate/RunTemplate.php' \
  'src/RunTemplate.php'
do
  url="https://raw.githubusercontent.com/${repo}/${sha}/${path}"
  echo "== ${path} =="
  if curl -fsSL "$url" | tee /tmp/runtemplate-source.php \
      | grep -n -C 8 -E 'function[[:space:]]+cloneAs[[:space:]]*\('; then
    echo "cloneAs found"
  else
    status=$?
    echo "No cloneAs match or source unavailable (status ${status})"
  fi
done

echo '== Candidate paths from upstream tree =='
curl -fsSL "https://github.com/${repo}/tree/${sha}" \
  | grep -oE 'href="[^"]*RunTemplate[^"]*\.php"' \
  | head -20 || true

Repository: VitexSoftware/multiflexi-web

Length of output: 755


🏁 Script executed:

set -u

repo='VitexSoftware/php-vitexsoftware-multiflexi-core'
sha='80eefa9362998179c5f68374ec5dc77fd605cc57'
url="https://raw.githubusercontent.com/${repo}/${sha}/src/MultiFlexi/RunTemplate.php"

echo "== ${url} =="
content="$(curl -fsSL "$url" 2>/tmp/curl-error || true)"
if [ -n "$content" ]; then
  printf '%s\n' "$content" | grep -n -C 8 -E 'function[[:space:]]+cloneAs[[:space:]]*\(' || true
  echo '== declarations =='
  printf '%s\n' "$content" | grep -n -E 'class[[:space:]]+RunTemplate|function[[:space:]]+[A-Za-z_][A-Za-z0-9_]*[[:space:]]*\(' | head -80
else
  cat /tmp/curl-error
fi

echo '== repository tree references =='
curl -fsSL "https://github.com/${repo}/tree/${sha}" 2>/tmp/tree-error \
  | grep -oE 'href="[^"]*RunTemplate[^"]*"' | head -20 || cat /tmp/tree-error

Repository: VitexSoftware/multiflexi-web

Length of output: 3089


Update the locked core package before calling cloneAs().

composer.lock pins vitexsoftware/multiflexi-core to 80eefa9362998179c5f68374ec5dc77fd605cc57, which does not define RunTemplate::cloneAs(). This call fails with an undefined-method error at runtime.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/runtemplateclone.php` at line 41, Update the locked multiflexi-core
dependency to a revision that defines RunTemplate::cloneAs(), then regenerate
composer.lock and verify the updated package is installed before the
$sourceTemplate->cloneAs($cloneName) call in runtemplateclone.php.


if ($newId) {
// Copy configurations
$configFields = $sourceTemplate->getRuntemplateEnvironment()->getFields();

$newConfigurator = new Configuration([], ['autoload' => false]);

foreach ($configFields as $field) {
$newConfigurator->insertToSQL([
'runtemplate_id' => $newId,
'app_id' => $templateData['app_id'],
'company_id' => $templateData['company_id'],
'name' => $field->getName(),
'value' => $field->getValue(),
'config_type' => $field->getType()]);
}

// Copy credential assignments
$credHelper = new RunTplCreds();
$credentials = $credHelper->getCredentialsForRuntemplate($sourceId)->fetchAll();

foreach ($credentials as $cred) {
$credHelper->insertToSQL([
'runtemplate_id' => $newId,
'credentials_id' => $cred['credentials_id'],
]);
}

WebPage::singleton()->addStatusMessage(
sprintf(
_('Runtemplate %s cloned as %s'),
_('Runtemplate %s cloned as %s (disabled β€” review and enable when ready)'),
$sourceTemplate->getRecordName(),
$cloneName,
),
Expand Down
Loading