Compare commits

..

5 Commits

Author SHA1 Message Date
8e677c05f3 working now 2023-06-06 01:58:54 -07:00
cca1cc8751 still not working 2023-06-01 08:20:10 -07:00
985514c51b build component works, php ini fixed 2023-05-31 16:57:49 -07:00
63183262d4 manifest and language is working so far 2023-05-31 12:25:05 -07:00
2e56d220d3 Working on component creator 2023-05-26 14:19:20 -07:00
15 changed files with 558 additions and 21 deletions

View File

@ -4,27 +4,75 @@ Joomla CMS.
Make sure the projectName is set correctly, it's very important, because it's used for git, docker, mysql and joomla. Make sure the projectName is set correctly, it's very important, because it's used for git, docker, mysql and joomla.
## Installation ## Quick Installation
1. Clone me ```git clone git@git.nickyeoman.com:nick/joomla.git projectName```
1. cd projectName
1. Setup your .env file ```mv env.sample .env``` then edit with your favorite editor.
1. Prepare your project for git ```bash bin/new_project.sh```
1. Run the containers to initialize ```sudo bash bin/docker_up.sh```
1. cli installer ```bash bin/setup_joomla_installer.sh```
1. Manually set Site Meta Description in [Administrator](http://localhost:8000/administrator/index.php?option=com_config)
1. Run ```sudo bash bin/finalize.sh```
## Working Environment ```bash
# STEP 1
# Clone the repo (change projectName to the name of your project)
git clone git@git.nickyeoman.com:nick/joomla.git projectName
# STEP 2
# Move into the dir
cd projectName
# STEP 3
# Setup your env file
mv env.sample .env
vi .env
# STEP 4
# Prepare your project for git
bash bin/new_project.sh
# STEP 5
# Run the containers to initialize
sudo bash bin/docker_up.sh
# STEP 6
# Joomla cli installer
sudo bash bin/setup_joomla_installer.sh
# STEP 7
# Manually set Site Meta Description in [Administrator](http://localhost:8000/administrator/index.php?option=com_config)
# Step 8
# Clean up and Config
sudo bash bin/finalize.sh
```
## Development Environment
Let's update our bash_profile with some alias: Let's update our bash_profile with some alias:
```bash ```bash
alias joomla='docker-compose exec -u www-data joomla php cli/joomla.php' alias joomla='docker-compose exec -u www-data joomla php cli/joomla.php'
``` ```
Allowing you to just run commands like this: ```joomla core:check-updates``` Allowing you to just run commands like this:
```bash
joomla core:check-updates
joomla site:down
joomla extension:list
joomla update:extensions:check
joomla cache:clean
```
## Create A Component
1. Move to the directory where you would like to keep the component. ```cd ~/joomla-components/```
1. Run component creator from your Joomla install. ```bash ~/projects/joomla/projectName/bin/create_component.sh```
1. Optionally save to git repo.
1. build the zip file by running bin/build_component.sh
## References ## References
* [Develop a component](https://docs.joomla.org/J4.x:Developing_an_MVC_Component/Developing_a_Basic_Component)
* [Minimal component](https://joomla.stackexchange.com/questions/22176/minimal-basic-structure-for-a-frontend-joomla-component-without-using-joomla-mvc)
* [Joomla CLI Cheatsheet](https://magazine.joomla.org/all-issues/june-2022/joomla-4-a-powerful-cli-application)
* [Joomla Twig](https://phproberto.github.io/joomla-twig/) * [Joomla Twig](https://phproberto.github.io/joomla-twig/)
### Component
* https://github.com/ceford/j4xdemos-com-mywalks/tree/master
* https://www.abdulwaheed.pk/en/blog/41-information-technology/44-joomla/302-how-to-create-joomla-4-component.html
* Can't get this one working either: https://www.techfry.com/resources/how-to-create-joomla-component
* https://docs.joomla.org/J4.x:Developing_an_MVC_Component/Introduction
* Can't get this one working [Develop a component](https://docs.joomla.org/J4.x:Developing_an_MVC_Component/Developing_a_Basic_Component)
* [Minimal component](https://joomla.stackexchange.com/questions/22176/minimal-basic-structure-for-a-frontend-joomla-component-without-using-joomla-mvc)

51
bin/build_component.sh Normal file
View File

@ -0,0 +1,51 @@
#!/bin/bash
###################################################################################################
#
# INSTRUCTIONS
# Move to the directory of the component
# Run this script with component name (com_name)
###################################################################################################
# Check if the component name is provided as the first parameter
if [ -n "$1" ]; then
componentName="$1"
else
# Prompt for the name of the component
read -p "Enter the name of the component (including com_): " componentName
fi
# Check if the component name starts with 'com_'
if [[ $componentName != com_* ]]; then
echo "Invalid component name. The name should start with 'com_'"
exit 1
fi
# Check if the component folder exists
if [ ! -d "$componentName" ]; then
echo "Component folder '$componentName' does not exist."
exit 1
fi
# Extract the name by removing the first four characters
name="${componentName:4}"
# Read the contents of $name/$name.xml file
xml_file="$componentName/$name.xml"
if [ -f "$xml_file" ]; then
xml_contents=$(cat "$xml_file")
else
echo "XML file '$xml_file' not found."
exit 1
fi
# Extract the version from the XML contents
regex="<version>(.*?)<\/version>"
if [[ $xml_contents =~ $regex ]]; then
version="${BASH_REMATCH[1]}"
else
echo "Version not found in the XML file."
exit 1
fi
zip_filename="$name-$version.zip"
cd "$componentName" && 7z a "../$zip_filename" *

View File

@ -0,0 +1,14 @@
#!/bin/bash
# Check if $name is set
if [[ -z "${name}" ]]; then
echo "Error: Variable \$name is not set. Exiting (displaycontroller.sh)."
exit 1
fi
cat <<EOM > admin/tmpl/${name}/default.php
<?php defined('_JEXEC') or die('Restricted Access'); ?>
<h2>Hello ${name}!</h2>
EOM

View File

@ -0,0 +1,29 @@
#!/bin/bash
# Check if $name is set
if [[ -z "${name}" ]]; then
echo "Error: Variable \$name is not set. Exiting (displaycontroller.sh)."
exit 1
fi
cat <<EOM > admin/src/Controller/DisplayController.php
<?php
namespace Harvst\\Component\\${name^}\\Administrator\\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\BaseController;
class DisplayController extends BaseController {
protected \$default_view = '${name}';
public function display(\$cachable = false, \$urlparams = array()) {
return parent::display(\$cachable, \$urlparams);
}
}
EOM

View File

@ -0,0 +1,8 @@
#!/bin/bash
cat <<EOM > admin/language/en-GB/en-GB.com_${name}.ini
; com_${name}
COM_${name^^}_DESCRIPTION="Placeholder description, edit in language file"
EOM

View File

@ -0,0 +1,50 @@
#!/bin/bash
current_date=$(date +'%B %Y')
current_year=$(date +'%Y')
# Check if JOOMLA_USER is set, otherwise prompt for it
if [ -z "$JOOMLA_USER" ]; then
read -p "Enter the Joomla user: " JOOMLA_USER
fi
# Check if EMAIL is set, otherwise prompt for it
if [ -z "$EMAIL" ]; then
read -p "Enter the email address: " EMAIL
fi
cat <<EOM > ${name}.xml
<?xml version="1.0" encoding="UTF-8"?>
<extension type="component" method="upgrade">
<name>${name}</name>
<creationDate>${current_date}</creationDate>
<author>${JOOMLA_USER}</author>
<authorEmail>${EMAIL}</authorEmail>
<authorUrl>https://www.example.com/</authorUrl>
<copyright>Copyright (C) ${current_year} ${JOOMLA_USER}, All rights reserved.</copyright>
<license>GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html</license>
<version>0.0.1</version>
<!-- The description is optional and defaults to the name -->
<description>COM_${name^^}_DESCRIPTION</description>
<namespace path="src/">Harvst\Component\\${name^}</namespace>
<administration>
<!-- The link that will appear in the Admin panel's "Components" menu -->
<menu link="index.php?option=com_${name}">${name^}</menu>
<files folder="admin">
<folder>language</folder>
<folder>services</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<languages folder="admin">
<!-- TODO: It's there but not working -->
<language tag="en-GB">language/en-GB/en-GB.com_${name}.ini</language>
</languages>
</administration>
</extension>
EOM

View File

@ -0,0 +1,35 @@
#!/bin/bash
cat <<EOM > admin/services/provider.php
<?php defined('_JEXEC') or die;
use Joomla\CMS\Dispatcher\ComponentDispatcherFactoryInterface;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
return new class implements ServiceProviderInterface {
public function register(Container \$container): void {
\$container->registerServiceProvider(new MVCFactory('\\\\Harvst\\\\Component\\\\${name^}'));
\$container->registerServiceProvider(new ComponentDispatcherFactory('\\\\Harvst\\\\Component\\\\${name^}'));
\$container->set(
ComponentInterface::class,
function (Container \$container) {
\$component = new MVCComponent(\$container->get(ComponentDispatcherFactoryInterface::class));
\$component->setMVCFactory(\$container->get(MVCFactoryInterface::class));
return \$component;
}
);
}
};
EOM

View File

@ -0,0 +1,26 @@
#!/bin/bash
# Check if $name is set
if [[ -z "${name}" ]]; then
echo "Error: Variable \$name is not set. Exiting (displaycontroller.sh)."
exit 1
fi
cat <<EOM > admin/src/View/${name^}/HtmlView.php
<?php
namespace Harvst\\Component\\${name^}\\Administrator\\View\\${name^};
defined('_JEXEC') or die;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
class HtmlView extends BaseHtmlView {
function display(\$tpl = null) {
parent::display(\$tpl);
}
}
EOM

73
bin/create_component.sh Normal file
View File

@ -0,0 +1,73 @@
#!/bin/bash
# create_component.sh componentName
# Determine the directory where the script is located
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
#################################################################################
# ENV File
#################################################################################
# Import variables from .env file
if [ -f "$script_dir/../.env" ]; then
read -p "Found .env file at '$script_dir/.env'. Press Enter to use it, or enter a different file path: " env_file
if [ -z "$env_file" ]; then
env_file="$script_dir/.env"
fi
else
read -p "Enter the path to the .env file: " env_file
fi
# Validate the .env file path
if [ ! -f "$env_file" ]; then
echo "Invalid .env file path. Please make sure the file exists."
exit 1
fi
# Source the variables from the .env file
source "$env_file"
echo "Variables from .env file imported successfully!"
#################################################################################
# Component Name
#################################################################################
# Check if the component name is provided as the first parameter
if [ -n "$1" ]; then
name="$1"
else
# Prompt for the name of the component
read -p "Enter the name of the component (one word in lowercase): " name
fi
# Validate the component name
if [[ ! "$name" =~ ^[a-z0-9_]+$ ]]; then
echo "Invalid component name. The name should be one word in lowercase with no spaces or special characters."
exit 1
fi
#################################################################################
# Do the work
#################################################################################
# Create the component directory
component_dir="com_${name}"
mkdir -p "$component_dir"
# Create the main component files
cd "$component_dir" || exit
mkdir -p site
mkdir -p admin/language/en-GB admin/services
mkdir -p admin/src/Controller admin/src/View/${name^} admin/tmpl/${name}
# Source the files for generating component files
source "$script_dir/component_parts/manifest.sh"
source "$script_dir/component_parts/language.sh"
source "$script_dir/component_parts/provider.sh"
source "$script_dir/component_parts/displaycontroller.sh"
source "$script_dir/component_parts/view.sh"
source "$script_dir/component_parts/defaultview.sh"
echo "Component framework generated successfully!"
echo "You should manually edit the manifest file before checkin"

View File

@ -24,6 +24,4 @@ rm -rf bin/inc_new_project
rm -rf bin/new_project.sh rm -rf bin/new_project.sh
rm -rf bin/setup_joomla_installer.sh rm -rf bin/setup_joomla_installer.sh
# Git echo "Now check the results and commit them to Git"
git add .
git commit -m"ran finalize"

View File

@ -34,7 +34,7 @@ docker-compose exec -u www-data joomla php installation/joomla.php install \
--site-name=$PROJECTNAME \ --site-name=$PROJECTNAME \
--admin-email=$EMAIL \ --admin-email=$EMAIL \
--admin-user=$JOOMLA_USER \ --admin-user=$JOOMLA_USER \
--admin-username=$JOOMLA_USER \ --admin-username=$JOOMLA_USERNAME \
--admin-password=$JOOMLA_PASSWORD \ --admin-password=$JOOMLA_PASSWORD \
--db-type=mysqli \ --db-type=mysqli \
--db-host=mariadb \ --db-host=mariadb \

View File

@ -22,7 +22,7 @@ services:
- joomla-db:/var/lib/mysql - joomla-db:/var/lib/mysql
joomla: joomla:
image: joomla:4.3.1 # https://hub.docker.com/_/joomla image: joomla:4.3.2 # https://hub.docker.com/_/joomla
restart: always restart: always
environment: environment:
JOOMLA_DB_HOST: mariadb JOOMLA_DB_HOST: mariadb
@ -31,6 +31,7 @@ services:
JOOMLA_DB_NAME: ${MYSQL_DATABASE} JOOMLA_DB_NAME: ${MYSQL_DATABASE}
volumes: volumes:
- ./html:/var/www/html - ./html:/var/www/html
- ./php/php.ini:/usr/local/etc/php/php.ini
ports: ports:
- "8000:80" - "8000:80"

75
docs/CLI.md Normal file
View File

@ -0,0 +1,75 @@
# CLI Cheatsheet
## Cache
```
cache:clean Clean expired cache entries
```
## Config
```
config:get Display the current value of a configuration option
config:set Set a value for a configuration option
```
## Core
```
core:check-updates Check for Joomla updates
core:update Update Joomla
```
## Database
```
database:export database:export
database:import Import the database
```
## Extension
```
extension:discover Discover extensions
extension:discover:install Install discovered extensions
extension:discover:list List discovered extensions
extension:install Install an extension from a URL or from a path
extension:list List installed extensions
extension:remove Remove an extension
```
## Finder
```
finder:index Purges and rebuild the index
Scheduler
scheduler:list List all scheduled tasks
scheduler:run Run one or more scheduled tasks
scheduler:state Enable, disable or trash a scheduled task
```
## Session
```
session:gc Perform session garbage collection
session:metadata:gc Perform session metadata garbage collection
```
## Site
```
site:down Put the site into offline mode
site:up Put the site into online mode
```
## Update
```
update:extensions:check Check for pending extension updates
update:joomla:remove-old-files Remove old system files
```
## User
```
user:add Add a user
user:addtogroup Add a user to a group
user:delete Delete a user
user:list List all users
user:removefromgroup Remove a user from a group
user:reset-password Change a user's password
```
## References
* [Joomla Magazine - Powerful cli](https://magazine.joomla.org/all-issues/june-2022/joomla-4-a-powerful-cli-application)

View File

@ -13,6 +13,7 @@ ACCESS_TOKEN=REPLACEME
# Joomla # Joomla
EMAIL=noreply@example.com EMAIL=noreply@example.com
JOOMLA_USER=admin JOOMLA_USER="John Doe"
JOOMLA_USERNAME=admin
# Passwords must be 12 characters long # Passwords must be 12 characters long
JOOMLA_PASSWORD=REPLACEME123 JOOMLA_PASSWORD=REPLACEME123

128
php/php.ini Normal file
View File

@ -0,0 +1,128 @@
[PHP]
engine = On
short_open_tag = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = -1
disable_functions =
disable_classes =
zend.enable_gc = On
zend.exception_ignore_args = On
zend.exception_string_param_max_len = 0
expose_php = On
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 800M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 400M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[CLI Server]
cli_server.color = On
[Pdo_mysql]
pdo_mysql.default_socket=
[mail function]
SMTP = localhost
smtp_port = 25
mail.add_x_header = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[MySQLi]
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mysqlnd]
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = Off
[PostgreSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[bcmath]
bcmath.scale = 0
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.cookie_samesite =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
[Assertion]
zend.assertions = -1
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
[ldap]
ldap.max_links = -1