Compare commits
No commits in common. "master" and "prod" have entirely different histories.
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -14,10 +14,3 @@ app/cake_eclipse_helper.php
|
|||
app/webroot/pdf/*
|
||||
app/webroot/attachments_files/*
|
||||
backups/*
|
||||
|
||||
# Go binaries
|
||||
go/server
|
||||
go/vault
|
||||
go/go.mod
|
||||
go/go.sum
|
||||
go/goose.env
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|||
|
||||
CMC Sales is a B2B sales management system for CMC Technologies. The codebase consists of:
|
||||
|
||||
- **Legacy CakePHP 1.2.5 application** (in `/php/`) - Primary business logic
|
||||
- **Modern Go API** (in `/go/`) - New development using sqlc and Gorilla Mux
|
||||
- **Legacy CakePHP 1.2.5 application** (2008-era) - Primary business logic
|
||||
- **Modern Go API** (in `/go-app/`) - New development using sqlc and Gorilla Mux
|
||||
|
||||
**Note**: Documentation also references a Django application that is not present in the current codebase.
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ gunzip < backups/backup_*.sql.gz | mariadb -h 127.0.0.1 -u cmc -p cmc
|
|||
### Go Application Development
|
||||
```bash
|
||||
# Navigate to Go app directory
|
||||
cd go
|
||||
cd go-app
|
||||
|
||||
# Configure private module access (first time only)
|
||||
go env -w GOPRIVATE=code.springupsoftware.com
|
||||
|
|
@ -80,7 +80,7 @@ make build
|
|||
### Go Application (Modern)
|
||||
- **Framework**: Gorilla Mux (HTTP router)
|
||||
- **Database**: sqlc for type-safe SQL queries
|
||||
- **Location**: `/go/`
|
||||
- **Location**: `/go-app/`
|
||||
- **Structure**:
|
||||
- `cmd/server/` - Main application entry point
|
||||
- `internal/cmc/handlers/` - HTTP request handlers
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
FROM golang:1.24-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go.mod and go.sum first
|
||||
COPY go/go.mod go/go.sum ./
|
||||
|
||||
# Download dependencies
|
||||
RUN go mod download
|
||||
|
||||
# Install Air for hot reload (pinned to v1.52.3 for Go 1.24 compatibility)
|
||||
RUN go install github.com/air-verse/air@v1.52.3
|
||||
# Install sqlc for SQL code generation
|
||||
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
||||
|
||||
# Copy source code
|
||||
COPY go/ .
|
||||
|
||||
# Generate sqlc code
|
||||
RUN sqlc generate
|
||||
|
||||
# Copy Air config
|
||||
COPY go/.air.toml .air.toml
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD ["air", "-c", ".air.toml"]
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
# Use the official PHP 5.6 Apache image for classic mod_php
|
||||
FROM php:5.6-apache
|
||||
|
||||
# Install required system libraries and PHP extensions for CakePHP
|
||||
RUN sed -i 's|http://deb.debian.org/debian|http://archive.debian.org/debian|g' /etc/apt/sources.list && \
|
||||
sed -i 's|http://security.debian.org/debian-security|http://archive.debian.org/debian-security|g' /etc/apt/sources.list && \
|
||||
sed -i '/stretch-updates/d' /etc/apt/sources.list && \
|
||||
echo 'Acquire::AllowInsecureRepositories "true";' > /etc/apt/apt.conf.d/99allow-insecure && \
|
||||
echo 'Acquire::AllowDowngradeToInsecureRepositories "true";' >> /etc/apt/apt.conf.d/99allow-insecure && \
|
||||
apt-get update && \
|
||||
apt-get install --allow-unauthenticated -y libc-client2007e-dev libkrb5-dev libpng-dev libjpeg-dev libfreetype6-dev libcurl4-openssl-dev libxml2-dev libssl-dev libmcrypt-dev libicu-dev && \
|
||||
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
|
||||
docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
|
||||
docker-php-ext-install mysqli pdo pdo_mysql mbstring gd curl imap
|
||||
|
||||
# Set environment variables.
|
||||
ENV HOME /root
|
||||
|
||||
# Define working directory.
|
||||
WORKDIR /root
|
||||
|
||||
ARG COMMIT
|
||||
ENV COMMIT_SHA=${COMMIT}
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
# Copy vhost config to Apache's sites-available
|
||||
ADD conf/apache-vhost.conf /etc/apache2/sites-available/cmc-sales.conf
|
||||
ADD conf/ripmime /bin/ripmime
|
||||
|
||||
RUN chmod +x /bin/ripmime \
|
||||
&& a2ensite cmc-sales \
|
||||
&& a2dissite 000-default \
|
||||
&& a2enmod rewrite \
|
||||
&& a2enmod headers
|
||||
|
||||
# Copy site into place.
|
||||
ADD php/ /var/www/cmc-sales
|
||||
ADD php/app/config/database_local.php /var/www/cmc-sales/app/config/database.php
|
||||
RUN mkdir -p /var/www/cmc-sales/app/tmp
|
||||
RUN mkdir -p /var/www/cmc-sales/app/tmp/logs
|
||||
RUN chmod -R 755 /var/www/cmc-sales/app/tmp
|
||||
|
||||
# Ensure CakePHP tmp directory is writable by web server
|
||||
RUN chmod -R 777 /var/www/cmc-sales/app/tmp
|
||||
# By default, simply start apache.
|
||||
CMD /usr/sbin/apache2ctl -D FOREGROUND
|
||||
|
|
@ -1,4 +1 @@
|
|||
FROM mariadb:latest
|
||||
|
||||
# Copy custom MariaDB configuration to disable strict mode
|
||||
COPY conf/mariadb-no-strict.cnf /etc/mysql/conf.d/
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ FROM golang:1.24-alpine AS builder
|
|||
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /app
|
||||
COPY go/go.mod go/go.sum ./
|
||||
COPY go-app/go.mod go-app/go.sum ./
|
||||
RUN go mod download
|
||||
COPY go/ .
|
||||
COPY go-app/ .
|
||||
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
||||
RUN sqlc generate
|
||||
RUN go mod tidy
|
||||
|
|
@ -16,8 +16,8 @@ RUN apk --no-cache add ca-certificates tzdata
|
|||
WORKDIR /root/
|
||||
COPY --from=builder /app/server .
|
||||
COPY --from=builder /app/vault .
|
||||
COPY go/templates ./templates
|
||||
COPY go/static ./static
|
||||
COPY go/.env.example .env
|
||||
COPY go-app/templates ./templates
|
||||
COPY go-app/static ./static
|
||||
COPY go-app/.env.example .env
|
||||
EXPOSE 8082
|
||||
CMD ["./server"]
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ RUN chmod +x /bin/ripmime \
|
|||
&& a2enmod headers
|
||||
|
||||
# Copy site into place.
|
||||
ADD php/ /var/www/cmc-sales
|
||||
ADD php/app/config/database.php /var/www/cmc-sales/app/config/database.php
|
||||
RUN mkdir -p /var/www/cmc-sales/app/tmp
|
||||
RUN mkdir -p /var/www/cmc-sales/app/tmp/logs
|
||||
ADD . /var/www/cmc-sales
|
||||
ADD app/config/database.php /var/www/cmc-sales/app/config/database.php
|
||||
RUN mkdir /var/www/cmc-sales/app/tmp
|
||||
RUN mkdir /var/www/cmc-sales/app/tmp/logs
|
||||
RUN chmod -R 755 /var/www/cmc-sales/app/tmp
|
||||
|
||||
# Ensure CakePHP tmp directory is writable by web server
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ FROM golang:1.24-alpine AS builder
|
|||
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /app
|
||||
COPY go/go.mod go/go.sum ./
|
||||
COPY go-app/go.mod go-app/go.sum ./
|
||||
RUN go mod download
|
||||
COPY go/ .
|
||||
COPY go-app/ .
|
||||
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
||||
RUN sqlc generate
|
||||
RUN go mod tidy
|
||||
|
|
@ -14,8 +14,8 @@ FROM alpine:latest
|
|||
RUN apk --no-cache add ca-certificates tzdata
|
||||
WORKDIR /root/
|
||||
COPY --from=builder /app/server .
|
||||
COPY go/templates ./templates
|
||||
COPY go/static ./static
|
||||
COPY go/.env.example .env
|
||||
COPY go-app/templates ./templates
|
||||
COPY go-app/static ./static
|
||||
COPY go-app/.env.example .env
|
||||
EXPOSE 8082
|
||||
CMD ["./server"]
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ RUN chmod +x /bin/ripmime \
|
|||
&& a2enmod headers
|
||||
|
||||
# Copy site into place.
|
||||
ADD php/ /var/www/cmc-sales
|
||||
ADD php/app/config/database_stg.php /var/www/cmc-sales/app/config/database.php
|
||||
ADD . /var/www/cmc-sales
|
||||
ADD app/config/database_stg.php /var/www/cmc-sales/app/config/database.php
|
||||
RUN mkdir -p /var/www/cmc-sales/app/tmp
|
||||
RUN mkdir -p /var/www/cmc-sales/app/tmp/logs
|
||||
RUN chmod -R 755 /var/www/cmc-sales/app/tmp
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ Deploy to staging or production using the scripts in the `deploy/` directory:
|
|||
|
||||
**Deploy to Staging:**
|
||||
```bash
|
||||
./scripts/deploy/deploy-stg.sh
|
||||
./deploy/deploy-stg.sh
|
||||
```
|
||||
|
||||
**Deploy to Production:**
|
||||
|
|
@ -88,8 +88,8 @@ Deploy to staging or production using the scripts in the `deploy/` directory:
|
|||
|
||||
**Rebuild without cache (useful after dependency changes):**
|
||||
```bash
|
||||
./scripts/deploy/deploy-prod.sh --no-cache
|
||||
./scripts/deploy/deploy-stg.sh --no-cache
|
||||
./deploy/deploy-prod.sh --no-cache
|
||||
./deploy/deploy-stg.sh --no-cache
|
||||
```
|
||||
|
||||
### How Deployment Works
|
||||
|
|
|
|||
0
php/app/.DS_Store → app/.DS_Store
vendored
0
php/app/.DS_Store → app/.DS_Store
vendored
|
|
@ -74,8 +74,8 @@ Cache::config('default', array(
|
|||
));
|
||||
|
||||
Configure::write('email_directory', '/var/www/emails');
|
||||
Configure::write('pdf_directory', $basedir.'webroot/pdf/');
|
||||
Configure::write('attachments_directory', $basedir.'webroot/attachments_files/');
|
||||
Configure::write('pdf_directory', $basedir.'/webroot/pdf/');
|
||||
Configure::write('attachments_directory', $basedir.'/webroot/attachments_files/');
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -190,8 +190,6 @@ Configure::write('Tailscale.autoCreateUsers', false);
|
|||
*/
|
||||
Configure::write('Tailscale.defaultAccessLevel', 'user');
|
||||
|
||||
/**
|
||||
* Set timezone to Australian Eastern Time
|
||||
* This handles both AEST and AEDT (daylight saving) automatically
|
||||
*/
|
||||
date_default_timezone_set('Australia/Sydney');
|
||||
|
||||
|
||||
|
||||
|
|
@ -39,83 +39,20 @@ class AttachmentsController extends AppController {
|
|||
|
||||
function add() {
|
||||
if (!empty($this->data)) {
|
||||
|
||||
// Check if file was uploaded
|
||||
if (empty($this->data['Attachment']['file']['tmp_name'])) {
|
||||
$error = 'No file uploaded';
|
||||
if (isset($this->data['Attachment']['file']['error'])) {
|
||||
$errorCodes = array(
|
||||
UPLOAD_ERR_INI_SIZE => 'File exceeds upload_max_filesize',
|
||||
UPLOAD_ERR_FORM_SIZE => 'File exceeds MAX_FILE_SIZE',
|
||||
UPLOAD_ERR_PARTIAL => 'File only partially uploaded',
|
||||
UPLOAD_ERR_NO_FILE => 'No file was uploaded',
|
||||
UPLOAD_ERR_NO_TMP_DIR => 'Missing temporary folder',
|
||||
UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
|
||||
UPLOAD_ERR_EXTENSION => 'File upload stopped by extension',
|
||||
);
|
||||
$errorCode = $this->data['Attachment']['file']['error'];
|
||||
$error = isset($errorCodes[$errorCode]) ? $errorCodes[$errorCode] : 'Unknown error: ' . $errorCode;
|
||||
}
|
||||
$this->Session->setFlash(__('File upload error: ' . $error, true));
|
||||
$principles = $this->Attachment->Principle->find('list');
|
||||
$this->set(compact('products', 'principles'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Proxy the upload request to the Go application
|
||||
$goHost = getenv('GO_APP_HOST');
|
||||
$goUrl = 'http://' . $goHost . '/go/attachments/upload';
|
||||
|
||||
// Prepare the multipart form data for the Go app
|
||||
$postFields = array();
|
||||
|
||||
$postFields['file'] = new CURLFile(
|
||||
$this->data['Attachment']['file']['tmp_name'],
|
||||
$this->data['Attachment']['file']['type'],
|
||||
$this->data['Attachment']['file']['name']
|
||||
);
|
||||
|
||||
if (!empty($this->data['Attachment']['name'])) {
|
||||
$postFields['name'] = $this->data['Attachment']['name'];
|
||||
$attachment = $this->Attachment->process_attachment($this->data);
|
||||
if(!$attachment) {
|
||||
$this->Session->setFlash('The Attachment could not be saved. The filename exists');
|
||||
}
|
||||
|
||||
if (!empty($this->data['Attachment']['description'])) {
|
||||
$postFields['description'] = $this->data['Attachment']['description'];
|
||||
}
|
||||
|
||||
if (!empty($this->data['Attachment']['principle_id'])) {
|
||||
$postFields['principle_id'] = $this->data['Attachment']['principle_id'];
|
||||
}
|
||||
|
||||
// Make the request to Go app
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $goUrl);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Accept: application/json'
|
||||
));
|
||||
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
$curlError = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($httpCode == 201) {
|
||||
$this->Session->setFlash(__('The Attachment has been saved', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
} else {
|
||||
$errorMsg = 'The Attachment could not be saved.';
|
||||
if ($curlError) {
|
||||
$errorMsg .= ' cURL Error: ' . $curlError;
|
||||
} elseif ($response) {
|
||||
$errorMsg .= ' Response: ' . $response;
|
||||
else {
|
||||
$this->Attachment->create();
|
||||
|
||||
if ($this->Attachment->save($attachment)) {
|
||||
$this->Session->setFlash(__('The Attachment has been saved', true));
|
||||
$this->redirect(array('action'=>'index'));
|
||||
} else {
|
||||
$errorMsg .= ' HTTP Code: ' . $httpCode;
|
||||
$this->Session->setFlash(__('The Attachment could not be saved. Please, try again.', true));
|
||||
}
|
||||
error_log('Attachment upload failed: ' . $errorMsg);
|
||||
$this->Session->setFlash(__($errorMsg, true));
|
||||
}
|
||||
}
|
||||
$principles = $this->Attachment->Principle->find('list');
|
||||
|
|
@ -540,10 +540,6 @@ ENDINSTRUCTIONS;
|
|||
$number_of_revisions = $this->Document->Quote->findCount('Quote.enquiry_id ='. $enquiryid);
|
||||
$newDoc['Document']['revision'] = $number_of_revisions;
|
||||
$newDoc['Document']['type'] = 'quote';
|
||||
|
||||
// user_id for the new revision will be the current user
|
||||
$currentUser = $this->GetCurrentUser();
|
||||
$newDoc['Document']['user_id'] = $currentUser['User']['id'];
|
||||
|
||||
|
||||
$newDoc['DocPage'] = $document['DocPage'];
|
||||
|
|
@ -600,6 +596,7 @@ ENDINSTRUCTIONS;
|
|||
// Store job IDs to be processed after the main save
|
||||
$newDoc['_job_ids'] = $job_ids;
|
||||
}
|
||||
print_r($newDoc);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -12,20 +12,11 @@ class EmailAttachmentsController extends AppController {
|
|||
// GET vault.cmctechnologies.com.au/filename
|
||||
// HTTP basic auth, or some sort of preshared key
|
||||
// service hits S3 if required. Cached on disk for $sometime
|
||||
|
||||
|
||||
$file = $this->EmailAttachment->findById($id);
|
||||
|
||||
// Try legacy emails directory first (where vault saves files)
|
||||
$file_path = '/var/www/emails';
|
||||
$full_path = $file_path."/".$file['EmailAttachment']['name'];
|
||||
|
||||
// Fallback to attachments directory if not found in emails
|
||||
if(!file_exists($full_path)) {
|
||||
$file_path = Configure::read('attachments_directory');
|
||||
$full_path = $file_path."/".$file['EmailAttachment']['name'];
|
||||
}
|
||||
|
||||
if(file_exists($full_path)) {
|
||||
$file_path = Configure::read('email_directory');
|
||||
if(file_exists($file_path."/".$file['EmailAttachment']['name'])) {
|
||||
|
||||
|
||||
|
||||
|
|
@ -42,13 +33,12 @@ class EmailAttachmentsController extends AppController {
|
|||
header('Content-length: ' . $file['EmailAttachment']['size']);
|
||||
header('Content-Disposition: attachment; filename='.$filename);
|
||||
|
||||
readfile($full_path);
|
||||
readfile($file_path."/".$file['EmailAttachment']['name']);
|
||||
|
||||
exit();
|
||||
}
|
||||
else {
|
||||
echo "ERROR: File Not Found";
|
||||
echo '\n';
|
||||
echo "ERROR!! : File Not Found";
|
||||
echo $file['EmailAttachment']['filename'];
|
||||
die();
|
||||
}
|
||||
|
|
@ -65,17 +55,9 @@ class EmailAttachmentsController extends AppController {
|
|||
$file = $this->EmailAttachment->find('first', array('conditions'=>array('EmailAttachment.id'=>$id)));
|
||||
//$this->set('attachment', $file);
|
||||
|
||||
// Try legacy emails directory first (where vault saves files)
|
||||
$file_path = '/var/www/emails';
|
||||
$full_path = $file_path."/".$file['EmailAttachment']['name'];
|
||||
$file_path = Configure::read('email_directory');
|
||||
|
||||
// Fallback to attachments directory if not found in emails
|
||||
if(!file_exists($full_path)) {
|
||||
$file_path = Configure::read('attachments_directory');
|
||||
$full_path = $file_path."/".$file['EmailAttachment']['name'];
|
||||
}
|
||||
|
||||
$contents = file_get_contents($full_path);
|
||||
$contents = file_get_contents($file_path."/".$file['EmailAttachment']['name']);
|
||||
|
||||
|
||||
if($file['EmailAttachment']['type'] == 'text/plain') {
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue