Skip to content

Commit 8b40791

Browse files
committed
Merge pull request #25 from VSEphpbb/components
Add more components
2 parents 8ca12ac + d4d033f commit 8b40791

20 files changed

Lines changed: 769 additions & 6 deletions

config/skeletons.yml

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,33 @@ services:
3636
tags:
3737
- { name: phpbb.skeleton.ext.skeleton }
3838

39+
phpbb.skeleton.ext.skeleton.mcp:
40+
class: phpbb\skeleton\skeleton
41+
arguments:
42+
- 'mcp'
43+
- false
44+
- []
45+
- ['mcp/main_info.php', 'mcp/main_module.php', 'styles/prosilver/template/mcp_demo_body.html', 'language/en/info_mcp_demo.php']
46+
tags:
47+
- { name: phpbb.skeleton.ext.skeleton }
48+
49+
phpbb.skeleton.ext.skeleton.ucp:
50+
class: phpbb\skeleton\skeleton
51+
arguments:
52+
- 'ucp'
53+
- false
54+
- []
55+
- ['ucp/main_info.php', 'ucp/main_module.php', 'styles/prosilver/template/ucp_demo_body.html', 'language/en/info_ucp_demo.php']
56+
tags:
57+
- { name: phpbb.skeleton.ext.skeleton }
58+
3959
phpbb.skeleton.ext.skeleton.migration:
4060
class: phpbb\skeleton\skeleton
4161
arguments:
4262
- 'migration'
4363
- false
4464
- []
45-
- ['migrations/install_module.php', 'migrations/install_user_schema.php']
65+
- ['migrations/install_acp_module.php', 'migrations/install_mcp_module.php', 'migrations/install_ucp_module.php', 'migrations/install_user_schema.php']
4666
tags:
4767
- { name: phpbb.skeleton.ext.skeleton }
4868

@@ -76,6 +96,26 @@ services:
7696
tags:
7797
- { name: phpbb.skeleton.ext.skeleton }
7898

99+
phpbb.skeleton.ext.skeleton.console:
100+
class: phpbb\skeleton\skeleton
101+
arguments:
102+
- 'console'
103+
- false
104+
- []
105+
- ['config/services.yml', 'console/command/demo.php', 'language/en/cli.php']
106+
tags:
107+
- { name: phpbb.skeleton.ext.skeleton }
108+
109+
phpbb.skeleton.ext.skeleton.cron:
110+
class: phpbb\skeleton\skeleton
111+
arguments:
112+
- 'cron'
113+
- false
114+
- []
115+
- ['config/services.yml', 'cron/task/demo.php', 'migrations/install_cron.php']
116+
tags:
117+
- { name: phpbb.skeleton.ext.skeleton }
118+
79119
phpbb.skeleton.ext.skeleton.tests:
80120
class: phpbb\skeleton\skeleton
81121
arguments:
@@ -95,3 +135,13 @@ services:
95135
- ['travis/prepare-phpbb.sh', '.travis.yml']
96136
tags:
97137
- { name: phpbb.skeleton.ext.skeleton }
138+
139+
phpbb.skeleton.ext.skeleton.build:
140+
class: phpbb\skeleton\skeleton
141+
arguments:
142+
- 'build'
143+
- false
144+
- []
145+
- ['build.xml']
146+
tags:
147+
- { name: phpbb.skeleton.ext.skeleton }

language/en/common.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@
7777
'SKELETON_QUESTION_COMPONENT_HTMLLISTENER' => 'Create sample styles listeners?',
7878
'SKELETON_QUESTION_COMPONENT_HTMLLISTENER_UI' => 'Styles listeners',
7979
'SKELETON_QUESTION_COMPONENT_ACP' => 'Create a sample ACP administration module?',
80-
'SKELETON_QUESTION_COMPONENT_ACP_UI' => 'Administration module (ACP)',
80+
'SKELETON_QUESTION_COMPONENT_ACP_UI' => 'Administration control panel (ACP)',
81+
'SKELETON_QUESTION_COMPONENT_MCP' => 'Create a sample MCP moderation module?',
82+
'SKELETON_QUESTION_COMPONENT_MCP_UI' => 'Moderator control panel (MCP)',
83+
'SKELETON_QUESTION_COMPONENT_UCP' => 'Create a sample UCP user module?',
84+
'SKELETON_QUESTION_COMPONENT_UCP_UI' => 'User control panel (UCP)',
8185
'SKELETON_QUESTION_COMPONENT_MIGRATION' => 'Create sample database migrations?',
8286
'SKELETON_QUESTION_COMPONENT_MIGRATION_UI' => 'Database migration',
8387
'SKELETON_QUESTION_COMPONENT_SERVICE' => 'Create a sample service?',
@@ -86,12 +90,16 @@
8690
'SKELETON_QUESTION_COMPONENT_CONTROLLER_UI' => 'Controller (front page)',
8791
'SKELETON_QUESTION_COMPONENT_EXT' => 'Create a sample ext.php?',
8892
'SKELETON_QUESTION_COMPONENT_EXT_UI' => 'Extension base (ext.php)',
93+
'SKELETON_QUESTION_COMPONENT_CONSOLE' => 'Create a sample console command?',
94+
'SKELETON_QUESTION_COMPONENT_CONSOLE_UI' => 'Console command',
95+
'SKELETON_QUESTION_COMPONENT_CRON' => 'Create a sample cron task?',
96+
'SKELETON_QUESTION_COMPONENT_CRON_UI' => 'Cron task',
8997
'SKELETON_QUESTION_COMPONENT_TESTS' => 'Create sample PHPUnit tests?',
9098
'SKELETON_QUESTION_COMPONENT_TESTS_UI' => 'PHPUnit tests',
9199
'SKELETON_QUESTION_COMPONENT_TRAVIS' => 'Create a sample for test execution on Travis-CI?',
92100
'SKELETON_QUESTION_COMPONENT_TRAVIS_UI' => 'Test execution on Travis-CI',
93-
'SKELETON_QUESTION_COMPONENT_BUILD' => 'Create a sample script to build packages for the customisation database?',
94-
'SKELETON_QUESTION_COMPONENT_BUILD_UI' => 'Script to build packages for the customisation database',
101+
'SKELETON_QUESTION_COMPONENT_BUILD' => 'Create a sample build script for phing?',
102+
'SKELETON_QUESTION_COMPONENT_BUILD_UI' => 'Build script (phing)',
95103

96104
'SKELETON_TITLE_EXTENSION_INFO' => 'Extension packaging',
97105
'SKELETON_TITLE_AUTHOR_INFO' => 'Authors',

skeleton/build.xml.tpl

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
{% set dir = '${' ~ 'dir}' %}
2+
{% set buildDir = '${' ~ 'build-directory}' %}
3+
{% set packageDir = '${' ~ 'package-directory}' %}
4+
{% set vendor = '${' ~ 'vendor-name}' %}
5+
{% set extension = '${' ~ 'extension-name}' %}
6+
{% set buildVersion = '${' ~ 'version}' %}
7+
{% set packageVersion = '${' ~ 'package-version}' %}
8+
{% set archiveVersion = '${' ~ 'archive-version}' %}
9+
{% set destination = '${' ~ 'destination-filename}' %}
10+
{% set dependencies = '${' ~ 'has-dependencies}' %}
11+
<?xml version="1.0" encoding="UTF-8"?>
12+
<project name="Skeleton Extension Builder" description="Builds an extension.zip from a git repository" default="all">
13+
<property name="vendor-name" value="{{ EXTENSION.vendor_name }}" />
14+
<property name="extension-name" value="{{ EXTENSION.extension_name }}" />
15+
<!--
16+
Only set this to "true" if you have dependencies in the composer.json,
17+
otherwise use "false".
18+
-->
19+
<property name="has-dependencies" value="false" />
20+
21+
<target name="clean-package">
22+
<!--
23+
Remove some unnecessary files/directories
24+
{{ dir }}/ is the folder of your extension, e.g. ext/acme/demo/
25+
-->
26+
<delete dir="{{ dir }}/tests" />
27+
<delete dir="{{ dir }}/travis" />
28+
29+
<delete file="{{ dir }}/.gitignore" />
30+
<delete file="{{ dir }}/.gitattributes" />
31+
<delete file="{{ dir }}/.travis.yml" />
32+
<delete file="{{ dir }}/build.xml" />
33+
<delete file="{{ dir }}/composer.lock" />
34+
<delete file="{{ dir }}/composer.phar" />
35+
<delete file="{{ dir }}/phpunit.xml.dist" />
36+
<delete file="{{ dir }}/README.md" />
37+
</target>
38+
39+
<!--
40+
TODO: DO NOT EDIT BELOW THIS LINE!!!!
41+
-->
42+
43+
<property name="version" value="HEAD" override="true" />
44+
<property name="build-directory" value="build" override="true" />
45+
<property name="package-directory" value="{{ buildDir }}/package/{{ vendor }}/{{ extension }}" />
46+
47+
<!-- These are the main targets which you will probably want to use -->
48+
<target name="all" depends="prepare-structure,package" />
49+
50+
<!--
51+
Clean up the build directory
52+
-->
53+
<target name="clean">
54+
<delete dir="{{ buildDir }}" />
55+
</target>
56+
57+
<!--
58+
Recreate the necessary folders
59+
-->
60+
<target name="prepare-structure" depends="clean">
61+
<mkdir dir="{{ buildDir }}" />
62+
<mkdir dir="{{ buildDir }}/checkout" />
63+
<mkdir dir="{{ buildDir }}/package" />
64+
<mkdir dir="{{ buildDir }}/package/{{ vendor }}" />
65+
<mkdir dir="{{ buildDir }}/package/{{ vendor }}/{{ extension }}" />
66+
<mkdir dir="{{ buildDir }}/upload" />
67+
</target>
68+
69+
<!--
70+
The real packaging
71+
-->
72+
<target name="package">
73+
<echo msg="Extracting {{ buildVersion }}" />
74+
75+
<phingcall target="git-checkout">
76+
<property name="archive-version" value="{{ buildVersion }}" />
77+
</phingcall>
78+
79+
<if>
80+
<equals arg1="{{ dependencies }}" arg2="1" />
81+
<then>
82+
<exec dir="{{ packageDir }}" command="php composer.phar install --no-dev"
83+
checkreturn="true" />
84+
</then>
85+
</if>
86+
87+
<phingcall target="clean-package">
88+
<property name="dir" value="{{ packageDir }}" />
89+
</phingcall>
90+
91+
<!-- Try setting the package version property from composer.json -->
92+
<exec dir="{{ packageDir }}"
93+
command='php -r "\$j = json_decode(file_get_contents(\"composer.json\")); echo (isset(\$j->version) ? \$j->version : \"{{ buildVersion }}\");"'
94+
checkreturn="true"
95+
outputProperty='package-version' />
96+
97+
<phingcall target="wrap-package">
98+
<property name="destination-filename" value="{{ buildDir }}/upload/{{ vendor }}_{{ extension }}_{{ packageVersion }}" />
99+
</phingcall>
100+
</target>
101+
102+
<!--
103+
Checkout a given version and install/clean the dependencies
104+
-->
105+
<target name="git-checkout">
106+
<echo msg="Getting archive for {{ archiveVersion }}" />
107+
108+
<exec command="git archive {{ archiveVersion }} --format zip --output {{ buildDir }}/checkout/{{ archiveVersion }}.zip"
109+
checkreturn="true" />
110+
<unzip file="{{ buildDir }}/checkout/{{ archiveVersion }}.zip" todir="{{ packageDir }}" />
111+
</target>
112+
113+
<!--
114+
Create the zip and tar ball
115+
-->
116+
<target name="wrap-package">
117+
<echo msg="Creating archives ({{ vendor }}/{{ extension }} {{ buildVersion }})" />
118+
<zip basedir="{{ buildDir }}/package/" destfile="{{ destination }}.zip" />
119+
</target>
120+
</project>

skeleton/config/services.yml.tpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,23 @@ services:
3232
- { name: event.listener }
3333

3434
<!-- ENDIF -->
35+
<!-- IF COMPONENT.console -->
36+
{EXTENSION.vendor_name}.{EXTENSION.extension_name}.command.demo:
37+
class: {EXTENSION.vendor_name}\{EXTENSION.extension_name}\console\command\demo
38+
arguments:
39+
- '@user'
40+
tags:
41+
- { name: console.command }
42+
43+
<!-- ENDIF -->
44+
<!-- IF COMPONENT.cron -->
45+
{EXTENSION.vendor_name}.{EXTENSION.extension_name}.cron.task.demo:
46+
class: {EXTENSION.vendor_name}\{EXTENSION.extension_name}\cron\task\demo
47+
arguments:
48+
- '@config'
49+
calls:
50+
- [set_name, [cron.task.demo]]
51+
tags:
52+
- { name: cron.task }
53+
54+
<!-- ENDIF -->
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
namespace {EXTENSION.vendor_name}\{EXTENSION.extension_name}\console\command;
15+
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
19+
class demo extends \phpbb\console\command\command
20+
{
21+
/** @var \phpbb\user */
22+
protected $user;
23+
24+
/**
25+
* Constructor
26+
*
27+
* @param \phpbb\user $user User instance (mostly for translation)
28+
*/
29+
public function __construct(\phpbb\user $user)
30+
{
31+
parent::__construct($user);
32+
33+
// Set up additional properties here
34+
}
35+
36+
/**
37+
* Configures the current command.
38+
*/
39+
protected function configure()
40+
{
41+
$this->user->add_lang_ext('{EXTENSION.vendor_name}/{EXTENSION.extension_name}', 'cli');
42+
$this
43+
->setName('acme:demo')
44+
->setDescription($this->user->lang('CLI_DEMO'))
45+
;
46+
}
47+
48+
/**
49+
* Executes the command acme:demo.
50+
*
51+
* @param InputInterface $input An InputInterface instance
52+
* @param OutputInterface $output An OutputInterface instance
53+
*
54+
* @return null
55+
*/
56+
protected function execute(InputInterface $input, OutputInterface $output)
57+
{
58+
$output->writeln($this->user->lang('CLI_DEMO_HELLO'));
59+
}
60+
}

skeleton/cron/task/demo.php.tpl

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
*
4+
* This file is part of the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
* For full copyright and license information, please see
10+
* the docs/CREDITS.txt file.
11+
*
12+
*/
13+
14+
namespace {EXTENSION.vendor_name}\{EXTENSION.extension_name}\cron\task;
15+
16+
/**
17+
* Acme demo cron task.
18+
*/
19+
class demo extends \phpbb\cron\task\base
20+
{
21+
/**
22+
* How often we run the cron (in seconds).
23+
* @var int
24+
*/
25+
protected $cron_frequency = 86400;
26+
27+
/** @var \phpbb\config\config */
28+
protected $config;
29+
30+
/**
31+
* Constructor
32+
*
33+
* @param \phpbb\config\config $config Config object
34+
*/
35+
public function __construct(\phpbb\config\config $config)
36+
{
37+
$this->config = $config;
38+
}
39+
40+
/**
41+
* Runs this cron task.
42+
*
43+
* @return null
44+
*/
45+
public function run()
46+
{
47+
// Run your cron actions here...
48+
49+
// Update the cron task run time here if it hasn't
50+
// already been done by your cron actions.
51+
$this->config->set('acme_cron_last_run', time(), false);
52+
}
53+
54+
/**
55+
* Returns whether this cron task can run, given current board configuration.
56+
*
57+
* For example, a cron task that prunes forums can only run when
58+
* forum pruning is enabled.
59+
*
60+
* @return bool
61+
*/
62+
public function is_runnable()
63+
{
64+
return true;
65+
}
66+
67+
/**
68+
* Returns whether this cron task should run now, because enough time
69+
* has passed since it was last run.
70+
*
71+
* @return bool
72+
*/
73+
public function should_run()
74+
{
75+
return $this->config['acme_cron_last_run'] < time() - $this->cron_frequency;
76+
}
77+
}

0 commit comments

Comments
 (0)