├── .github └── workflows │ ├── index-wiki.yml │ └── pull-request.yml ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── _travis ├── install.sh ├── script.sh └── setup.sh ├── composer.json └── src └── Joomlatools ├── Composer ├── ComposerInstaller.php ├── ExtensionInstaller.php ├── Plugin.php └── TaskQueue.php └── Joomla ├── Application.php ├── Bootstrapper.php ├── Legacy └── JLoggerStderr.php └── Util.php /.github/workflows/index-wiki.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Index Wiki 3 | 4 | on: 5 | gollum: 6 | workflow_dispatch: 7 | 8 | jobs: 9 | index: 10 | 11 | name: Create Wiki Filesystem Index 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Checkout wiki code from Github 16 | uses: actions/checkout@v3 17 | with: 18 | repository: ${{github.repository}}.wiki 19 | fetch-depth: 0 20 | 21 | - name: Create index 22 | run: | 23 | git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format="{},%h,%aI,%aN,%aE" {} | \ 24 | jq -Rs 'split("\n")[:-1] | map({ 25 | file: (. | split(",")[0]), 26 | hash: (. | split(",")[1]), 27 | author_date: (. | split(",")[2]), 28 | author_name: (. | split(",")[3]), 29 | author_email: (. | split(",")[4]), 30 | })' > _Index.json 31 | 32 | - name: Commit index 33 | uses: stefanzweifel/git-auto-commit-action@v4 34 | with: 35 | commit_message: Update Wiki Index 36 | -------------------------------------------------------------------------------- /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Create a pull request 3 | 4 | on: 5 | create: 6 | 7 | jobs: 8 | pull-request: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | 13 | 14 | - name: Only run on branches whose names start with feature/ or hotfix/ 15 | if: startsWith(github.ref, 'refs/heads/feature') || startsWith(github.ref, 'refs/heads/hotfix') 16 | shell: bash 17 | run: echo "ISSUE_ID=$(echo $GITHUB_REF | grep -o -E '[0-9]+' | head -1 | sed -e 's/^0\+//')" >> $GITHUB_ENV 18 | 19 | 20 | - name: Get issue data 21 | uses: octokit/request-action@v2.x 22 | if: ${{ env.ISSUE_ID }} 23 | id: issue 24 | with: 25 | route: GET /repos/${{ github.repository }}/issues/${{ env.ISSUE_ID }} 26 | env: 27 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 28 | 29 | 30 | - name: Gather PR data 31 | if: ${{ steps.issue.outputs.data }} 32 | id: pr_data 33 | shell: bash 34 | run: | 35 | echo "::set-output name=title::$(echo $json_var | jq '.title' --raw-output )" 36 | echo "::set-output name=body::Closes #$(echo $json_var | jq '.number' --raw-output)" 37 | echo "::set-output name=assignee::$(echo $json_var | jq '[.assignees[].login] | join(",")' --raw-output --compact-output)" 38 | echo "::set-output name=label::$(echo $json_var | jq '[.labels[].name] | join(",")' --raw-output --compact-output)" 39 | echo "::set-output name=milestone::$(echo $json_var | jq '[.milestone.title] | join(",")' --raw-output --compact-output)" 40 | env: 41 | json_var: ${{ steps.issue.outputs.data }} 42 | 43 | 44 | - name: Create pull request 45 | if: ${{ steps.issue.outputs.data }} 46 | uses: repo-sync/pull-request@v2 47 | with: 48 | pr_title: ${{ steps.pr_data.outputs.title }} 49 | pr_body: ${{ steps.pr_data.outputs.body }} 50 | pr_assignee: ${{ steps.pr_data.outputs.assignee }} 51 | pr_label: ${{ steps.pr_data.outputs.label }} 52 | pr_milestone: ${{ steps.pr_data.outputs.milestone }} 53 | github_token: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | sudo: false 3 | 4 | php: 5 | - 7.1 6 | env: 7 | - RELEASE=3.6 REPO=https://github.com/joomla/joomla-cms.git 8 | - RELEASE=3.7 REPO=https://github.com/joomla/joomla-cms.git 9 | - RELEASE=latest REPO=https://github.com/joomla/joomla-cms.git 10 | - RELEASE=latest REPO=https://github.com/joomlatools/joomlatools-platform.git 11 | 12 | services: 13 | - mysql 14 | 15 | git: 16 | depth: 999999 # We can't use a shallow clone for testing. See: https://github.com/travis-ci/travis-ci/issues/4942#issuecomment-159132444 17 | 18 | before_install: 19 | - export DOCUMENTROOT=/tmp/www/ 20 | - chmod +x $TRAVIS_BUILD_DIR/_travis/install.sh 21 | - $TRAVIS_BUILD_DIR/_travis/install.sh 22 | 23 | before_script: 24 | - chmod +x $TRAVIS_BUILD_DIR/_travis/setup.sh 25 | - $TRAVIS_BUILD_DIR/_travis/setup.sh 26 | 27 | script: 28 | - chmod +x $TRAVIS_BUILD_DIR/_travis/script.sh 29 | - $TRAVIS_BUILD_DIR/_travis/script.sh -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | This changelog references the relevant changes (bug and security fixes) done 5 | in 1.x versions. 6 | 7 | To get the diff for a specific change, go to https://github.com/joomlatools/joomlatools-composer/commit/xxx where xxx is the change hash. 8 | To view the diff between two versions, go to https://github.com/joomlatools/joomlatools-composer/compare/v1.0.0...v1.0.1 9 | 10 | * 1.1.6 (2020-08-19) 11 | * Reset the phar wrapper [#44](https://github.com/joomlatools/joomlatools-composer/issues/44) 12 | * Only run stream_wrapper_restore on Joomla 3.9 [#48](https://github.com/joomlatools/joomlatools-composer/issues/48) 13 | 14 | * 1.1.5 (2019-01-17) 15 | * Media files not properly moved in Joomlatools Platform [#42](https://github.com/joomlatools/joomlatools-composer/issues/42) 16 | 17 | * 1.1.4 (2018-10-03) 18 | * Fire upgrade if extension is already registered [#23](https://github.com/joomlatools/joomlatools-composer/issues/23) 19 | 20 | * 1.1.3 (2018-09-25) 21 | * Fix language package installations [#40](https://github.com/joomlatools/joomlatools-composer/pull/40) 22 | 23 | * 1.1.2 (2017-09-25) 24 | * Fixed Joomla 3.8 compatibility [#34](https://github.com/joomlatools/joomlatools-composer/issues/34) 25 | * Added Initial implementation of Travis CI tests [#35](https://github.com/joomlatools/joomlatools-composer/issues/35) 26 | 27 | * 1.1.1 (2017-05-02) 28 | * Fixed Joomla 3.7 compatibility [#30](https://github.com/joomlatools/joomlatools-composer/issues/30) 29 | 30 | * 1.1.0 (2017-01-18) 31 | * Added `joomlatools-extension` as a Composer package type [#29](https://github.com/joomlatools/joomlatools-composer/issues/29) 32 | * Added manifest copy support to extension installer [#28](https://github.com/joomlatools/joomlatools-composer/issues/28) 33 | * Added support for reusable Joomlatools Framework components [#27](https://github.com/joomlatools/joomlatools-composer/issues/27) 34 | * Added fake redirect() method [#25](https://github.com/joomlatools/joomlatools-composer/pull/25) 35 | 36 | * 1.0.8 (2015-12-01) 37 | * Improved: Rename repository and package [#17](https://github.com/joomlatools/joomlatools-composer/issues/17) 38 | 39 | * 1.0.7 (2015-09-06) 40 | * Fixed: Version check for [joomla-platform](http://github.com/joomlatools/joomla-platform) 41 | * Fixed: Throw an exception if trying to install outside of a Joomla installation (#13) 42 | * Added: Automatically enable plugins after installation (#10) 43 | * Improved: Bootstrap logic for [joomla-platform](http://github.com/joomlatools/joomla-platform) 44 | 45 | * 1.0.6 (2015-07-03) 46 | * Fixed: Use `vendor` directory instead of `tmp` to store packages. (#6) 47 | * Added: Support for joomla-platform. (#7) 48 | * Added: Uninstall support. (#9) 49 | * Fixed: Updated changelog. 50 | 51 | * 1.0.5 (2015-06-11) 52 | * Fixed: Restrict console-plugin-api version to ^1.0 (see [this issue](https://github.com/composer/composer/issues/4085)) 53 | 54 | * 1.0.4 (2015-05-19) 55 | * Added: Enable Joomla logging (PR #4) 56 | 57 | * 1.0.3 (2015-05-02) 58 | * Improved: Ensure compatibility with both latest Composer (Composer version 1.0-dev (1cb427ff5c0b977468643a39436f3b0a356fc8eb) 2015-04-26) and previous versions. (PR #5) 59 | 60 | * 1.0.2 (2015-03-03) 61 | * Fixed: Fix call to undefined function Composer\Autoload\includeFile() error in Joomla 3.4 62 | 63 | * 1.0.1 (2014-01-12) 64 | * Fixed: Joomla 3.2 compatibility ([pull request #2](https://github.com/joomlatools/joomlatools-composer/pull/2) by [ienev](https://github.com/ienev)) 65 | * Fixed: Fix Joomla 3.x debug plugin crashing after execution. 66 | 67 | * 1.0.0 (2013-11-05) 68 | * Added: Initial release: Composer support for Joomla 2.5 and 3.0 69 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Please read [Contributing to Joomlatools Projects](http://developer.joomlatools.com/contribute.html) 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | GNU GENERAL PUBLIC LICENSE 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. [http://fsf.org/] 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for 12 | software and other kinds of works. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | the GNU General Public License is intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. We, the Free Software Foundation, use the 19 | GNU General Public License for most of our software; it applies also to 20 | any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not 24 | price. Our General Public Licenses are designed to make sure that you 25 | have the freedom to distribute copies of free software (and charge for 26 | them if you wish), that you receive source code or can get it if you 27 | want it, that you can change the software or use pieces of it in new 28 | free programs, and that you know you can do these things. 29 | 30 | To protect your rights, we need to prevent others from denying you 31 | these rights or asking you to surrender the rights. Therefore, you have 32 | certain responsibilities if you distribute copies of the software, or if 33 | you modify it: responsibilities to respect the freedom of others. 34 | 35 | For example, if you distribute copies of such a program, whether 36 | gratis or for a fee, you must pass on to the recipients the same 37 | freedoms that you received. You must make sure that they, too, receive 38 | or can get the source code. And you must show them these terms so they 39 | know their rights. 40 | 41 | Developers that use the GNU GPL protect your rights with two steps: 42 | (1) assert copyright on the software, and (2) offer you this License 43 | giving you legal permission to copy, distribute and/or modify it. 44 | 45 | For the developers' and authors' protection, the GPL clearly explains 46 | that there is no warranty for this free software. For both users' and 47 | authors' sake, the GPL requires that modified versions be marked as 48 | changed, so that their problems will not be attributed erroneously to 49 | authors of previous versions. 50 | 51 | Some devices are designed to deny users access to install or run 52 | modified versions of the software inside them, although the manufacturer 53 | can do so. This is fundamentally incompatible with the aim of 54 | protecting users' freedom to change the software. The systematic 55 | pattern of such abuse occurs in the area of products for individuals to 56 | use, which is precisely where it is most unacceptable. Therefore, we 57 | have designed this version of the GPL to prohibit the practice for those 58 | products. If such problems arise substantially in other domains, we 59 | stand ready to extend this provision to those domains in future versions 60 | of the GPL, as needed to protect the freedom of users. 61 | 62 | Finally, every program is threatened constantly by software patents. 63 | States should not allow patents to restrict development and use of 64 | software on general-purpose computers, but in those that do, we wish to 65 | avoid the special danger that patents applied to a free program could 66 | make it effectively proprietary. To prevent this, the GPL assures that 67 | patents cannot be used to render the program non-free. 68 | 69 | The precise terms and conditions for copying, distribution and 70 | modification follow. 71 | 72 | TERMS AND CONDITIONS 73 | 74 | 0. Definitions. 75 | 76 | "This License" refers to version 3 of the GNU General Public License. 77 | 78 | "Copyright" also means copyright-like laws that apply to other kinds of 79 | works, such as semiconductor masks. 80 | 81 | "The Program" refers to any copyrightable work licensed under this 82 | License. Each licensee is addressed as "you". "Licensees" and 83 | "recipients" may be individuals or organizations. 84 | 85 | To "modify" a work means to copy from or adapt all or part of the work 86 | in a fashion requiring copyright permission, other than the making of an 87 | exact copy. The resulting work is called a "modified version" of the 88 | earlier work or a work "based on" the earlier work. 89 | 90 | A "covered work" means either the unmodified Program or a work based 91 | on the Program. 92 | 93 | To "propagate" a work means to do anything with it that, without 94 | permission, would make you directly or secondarily liable for 95 | infringement under applicable copyright law, except executing it on a 96 | computer or modifying a private copy. Propagation includes copying, 97 | distribution (with or without modification), making available to the 98 | public, and in some countries other activities as well. 99 | 100 | To "convey" a work means any kind of propagation that enables other 101 | parties to make or receive copies. Mere interaction with a user through 102 | a computer network, with no transfer of a copy, is not conveying. 103 | 104 | An interactive user interface displays "Appropriate Legal Notices" 105 | to the extent that it includes a convenient and prominently visible 106 | feature that (1) displays an appropriate copyright notice, and (2) 107 | tells the user that there is no warranty for the work (except to the 108 | extent that warranties are provided), that licensees may convey the 109 | work under this License, and how to view a copy of this License. If 110 | the interface presents a list of user commands or options, such as a 111 | menu, a prominent item in the list meets this criterion. 112 | 113 | 1. Source Code. 114 | 115 | The "source code" for a work means the preferred form of the work 116 | for making modifications to it. "Object code" means any non-source 117 | form of a work. 118 | 119 | A "Standard Interface" means an interface that either is an official 120 | standard defined by a recognized standards body, or, in the case of 121 | interfaces specified for a particular programming language, one that 122 | is widely used among developers working in that language. 123 | 124 | The "System Libraries" of an executable work include anything, other 125 | than the work as a whole, that (a) is included in the normal form of 126 | packaging a Major Component, but which is not part of that Major 127 | Component, and (b) serves only to enable use of the work with that 128 | Major Component, or to implement a Standard Interface for which an 129 | implementation is available to the public in source code form. A 130 | "Major Component", in this context, means a major essential component 131 | (kernel, window system, and so on) of the specific operating system 132 | (if any) on which the executable work runs, or a compiler used to 133 | produce the work, or an object code interpreter used to run it. 134 | 135 | The "Corresponding Source" for a work in object code form means all 136 | the source code needed to generate, install, and (for an executable 137 | work) run the object code and to modify the work, including scripts to 138 | control those activities. However, it does not include the work's 139 | System Libraries, or general-purpose tools or generally available free 140 | programs which are used unmodified in performing those activities but 141 | which are not part of the work. For example, Corresponding Source 142 | includes interface definition files associated with source files for 143 | the work, and the source code for shared libraries and dynamically 144 | linked subprograms that the work is specifically designed to require, 145 | such as by intimate data communication or control flow between those 146 | subprograms and other parts of the work. 147 | 148 | The Corresponding Source need not include anything that users 149 | can regenerate automatically from other parts of the Corresponding 150 | Source. 151 | 152 | The Corresponding Source for a work in source code form is that 153 | same work. 154 | 155 | 2. Basic Permissions. 156 | 157 | All rights granted under this License are granted for the term of 158 | copyright on the Program, and are irrevocable provided the stated 159 | conditions are met. This License explicitly affirms your unlimited 160 | permission to run the unmodified Program. The output from running a 161 | covered work is covered by this License only if the output, given its 162 | content, constitutes a covered work. This License acknowledges your 163 | rights of fair use or other equivalent, as provided by copyright law. 164 | 165 | You may make, run and propagate covered works that you do not 166 | convey, without conditions so long as your license otherwise remains 167 | in force. You may convey covered works to others for the sole purpose 168 | of having them make modifications exclusively for you, or provide you 169 | with facilities for running those works, provided that you comply with 170 | the terms of this License in conveying all material for which you do 171 | not control copyright. Those thus making or running the covered works 172 | for you must do so exclusively on your behalf, under your direction 173 | and control, on terms that prohibit them from making any copies of 174 | your copyrighted material outside their relationship with you. 175 | 176 | Conveying under any other circumstances is permitted solely under 177 | the conditions stated below. Sublicensing is not allowed; section 10 178 | makes it unnecessary. 179 | 180 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 181 | 182 | No covered work shall be deemed part of an effective technological 183 | measure under any applicable law fulfilling obligations under article 184 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 185 | similar laws prohibiting or restricting circumvention of such 186 | measures. 187 | 188 | When you convey a covered work, you waive any legal power to forbid 189 | circumvention of technological measures to the extent such circumvention 190 | is effected by exercising rights under this License with respect to 191 | the covered work, and you disclaim any intention to limit operation or 192 | modification of the work as a means of enforcing, against the work's 193 | users, your or third parties' legal rights to forbid circumvention of 194 | technological measures. 195 | 196 | 4. Conveying Verbatim Copies. 197 | 198 | You may convey verbatim copies of the Program's source code as you 199 | receive it, in any medium, provided that you conspicuously and 200 | appropriately publish on each copy an appropriate copyright notice; 201 | keep intact all notices stating that this License and any 202 | non-permissive terms added in accord with section 7 apply to the code; 203 | keep intact all notices of the absence of any warranty; and give all 204 | recipients a copy of this License along with the Program. 205 | 206 | You may charge any price or no price for each copy that you convey, 207 | and you may offer support or warranty protection for a fee. 208 | 209 | 5. Conveying Modified Source Versions. 210 | 211 | You may convey a work based on the Program, or the modifications to 212 | produce it from the Program, in the form of source code under the 213 | terms of section 4, provided that you also meet all of these conditions: 214 | 215 | a) The work must carry prominent notices stating that you modified 216 | it, and giving a relevant date. 217 | 218 | b) The work must carry prominent notices stating that it is 219 | released under this License and any conditions added under section 220 | 7. This requirement modifies the requirement in section 4 to 221 | "keep intact all notices". 222 | 223 | c) You must license the entire work, as a whole, under this 224 | License to anyone who comes into possession of a copy. This 225 | License will therefore apply, along with any applicable section 7 226 | additional terms, to the whole of the work, and all its parts, 227 | regardless of how they are packaged. This License gives no 228 | permission to license the work in any other way, but it does not 229 | invalidate such permission if you have separately received it. 230 | 231 | d) If the work has interactive user interfaces, each must display 232 | Appropriate Legal Notices; however, if the Program has interactive 233 | interfaces that do not display Appropriate Legal Notices, your 234 | work need not make them do so. 235 | 236 | A compilation of a covered work with other separate and independent 237 | works, which are not by their nature extensions of the covered work, 238 | and which are not combined with it such as to form a larger program, 239 | in or on a volume of a storage or distribution medium, is called an 240 | "aggregate" if the compilation and its resulting copyright are not 241 | used to limit the access or legal rights of the compilation's users 242 | beyond what the individual works permit. Inclusion of a covered work 243 | in an aggregate does not cause this License to apply to the other 244 | parts of the aggregate. 245 | 246 | 6. Conveying Non-Source Forms. 247 | 248 | You may convey a covered work in object code form under the terms 249 | of sections 4 and 5, provided that you also convey the 250 | machine-readable Corresponding Source under the terms of this License, 251 | in one of these ways: 252 | 253 | a) Convey the object code in, or embodied in, a physical product 254 | (including a physical distribution medium), accompanied by the 255 | Corresponding Source fixed on a durable physical medium 256 | customarily used for software interchange. 257 | 258 | b) Convey the object code in, or embodied in, a physical product 259 | (including a physical distribution medium), accompanied by a 260 | written offer, valid for at least three years and valid for as 261 | long as you offer spare parts or customer support for that product 262 | model, to give anyone who possesses the object code either (1) a 263 | copy of the Corresponding Source for all the software in the 264 | product that is covered by this License, on a durable physical 265 | medium customarily used for software interchange, for a price no 266 | more than your reasonable cost of physically performing this 267 | conveying of source, or (2) access to copy the 268 | Corresponding Source from a network server at no charge. 269 | 270 | c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 275 | 276 | d) Convey the object code by offering access from a designated 277 | place (gratis or for a charge), and offer equivalent access to the 278 | Corresponding Source in the same way through the same place at no 279 | further charge. You need not require recipients to copy the 280 | Corresponding Source along with the object code. If the place to 281 | copy the object code is a network server, the Corresponding Source 282 | may be on a different server (operated by you or a third party) 283 | that supports equivalent copying facilities, provided you maintain 284 | clear directions next to the object code saying where to find the 285 | Corresponding Source. Regardless of what server hosts the 286 | Corresponding Source, you remain obligated to ensure that it is 287 | available for as long as needed to satisfy these requirements. 288 | 289 | e) Convey the object code using peer-to-peer transmission, provided 290 | you inform other peers where the object code and Corresponding 291 | Source of the work are being offered to the general public at no 292 | charge under subsection 6d. 293 | 294 | A separable portion of the object code, whose source code is excluded 295 | from the Corresponding Source as a System Library, need not be 296 | included in conveying the object code work. 297 | 298 | A "User Product" is either (1) a "consumer product", which means any 299 | tangible personal property which is normally used for personal, family, 300 | or household purposes, or (2) anything designed or sold for incorporation 301 | into a dwelling. In determining whether a product is a consumer product, 302 | doubtful cases shall be resolved in favor of coverage. For a particular 303 | product received by a particular user, "normally used" refers to a 304 | typical or common use of that class of product, regardless of the status 305 | of the particular user or of the way in which the particular user 306 | actually uses, or expects or is expected to use, the product. A product 307 | is a consumer product regardless of whether the product has substantial 308 | commercial, industrial or non-consumer uses, unless such uses represent 309 | the only significant mode of use of the product. 310 | 311 | "Installation Information" for a User Product means any methods, 312 | procedures, authorization keys, or other information required to install 313 | and execute modified versions of a covered work in that User Product from 314 | a modified version of its Corresponding Source. The information must 315 | suffice to ensure that the continued functioning of the modified object 316 | code is in no case prevented or interfered with solely because 317 | modification has been made. 318 | 319 | If you convey an object code work under this section in, or with, or 320 | specifically for use in, a User Product, and the conveying occurs as 321 | part of a transaction in which the right of possession and use of the 322 | User Product is transferred to the recipient in perpetuity or for a 323 | fixed term (regardless of how the transaction is characterized), the 324 | Corresponding Source conveyed under this section must be accompanied 325 | by the Installation Information. But this requirement does not apply 326 | if neither you nor any third party retains the ability to install 327 | modified object code on the User Product (for example, the work has 328 | been installed in ROM). 329 | 330 | The requirement to provide Installation Information does not include a 331 | requirement to continue to provide support service, warranty, or updates 332 | for a work that has been modified or installed by the recipient, or for 333 | the User Product in which it has been modified or installed. Access to a 334 | network may be denied when the modification itself materially and 335 | adversely affects the operation of the network or violates the rules and 336 | protocols for communication across the network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders of 364 | that material) supplement the terms of this License with terms: 365 | 366 | a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 368 | 369 | b) Requiring preservation of specified reasonable legal notices or 370 | author attributions in that material or in the Appropriate Legal 371 | Notices displayed by works containing it; or 372 | 373 | c) Prohibiting misrepresentation of the origin of that material, or 374 | requiring that modified versions of such material be marked in 375 | reasonable ways as different from the original version; or 376 | 377 | d) Limiting the use for publicity purposes of names of licensors or 378 | authors of the material; or 379 | 380 | e) Declining to grant rights under trademark law for use of some 381 | trade names, trademarks, or service marks; or 382 | 383 | f) Requiring indemnification of licensors and authors of that 384 | material by anyone who conveys the material (or modified versions of 385 | it) with contractual assumptions of liability to the recipient, for 386 | any liability that these contractual assumptions directly impose on 387 | those licensors and authors. 388 | 389 | All other non-permissive additional terms are considered "further 390 | restrictions" within the meaning of section 10. If the Program as you 391 | received it, or any part of it, contains a notice stating that it is 392 | governed by this License along with a term that is a further 393 | restriction, you may remove that term. If a license document contains 394 | a further restriction but permits relicensing or conveying under this 395 | License, you may add to a covered work material governed by the terms 396 | of that license document, provided that the further restriction does 397 | not survive such relicensing or conveying. 398 | 399 | If you add terms to a covered work in accord with this section, you 400 | must place, in the relevant source files, a statement of the 401 | additional terms that apply to those files, or a notice indicating 402 | where to find the applicable terms. 403 | 404 | Additional terms, permissive or non-permissive, may be stated in the 405 | form of a separately written license, or stated as exceptions; 406 | the above requirements apply either way. 407 | 408 | 8. Termination. 409 | 410 | You may not propagate or modify a covered work except as expressly 411 | provided under this License. Any attempt otherwise to propagate or 412 | modify it is void, and will automatically terminate your rights under 413 | this License (including any patent licenses granted under the third 414 | paragraph of section 11). 415 | 416 | However, if you cease all violation of this License, then your 417 | license from a particular copyright holder is reinstated (a) 418 | provisionally, unless and until the copyright holder explicitly and 419 | finally terminates your license, and (b) permanently, if the copyright 420 | holder fails to notify you of the violation by some reasonable means 421 | prior to 60 days after the cessation. 422 | 423 | Moreover, your license from a particular copyright holder is 424 | reinstated permanently if the copyright holder notifies you of the 425 | violation by some reasonable means, this is the first time you have 426 | received notice of violation of this License (for any work) from that 427 | copyright holder, and you cure the violation prior to 30 days after 428 | your receipt of the notice. 429 | 430 | Termination of your rights under this section does not terminate the 431 | licenses of parties who have received copies or rights from you under 432 | this License. If your rights have been terminated and not permanently 433 | reinstated, you do not qualify to receive new licenses for the same 434 | material under section 10. 435 | 436 | 9. Acceptance Not Required for Having Copies. 437 | 438 | You are not required to accept this License in order to receive or 439 | run a copy of the Program. Ancillary propagation of a covered work 440 | occurring solely as a consequence of using peer-to-peer transmission 441 | to receive a copy likewise does not require acceptance. However, 442 | nothing other than this License grants you permission to propagate or 443 | modify any covered work. These actions infringe copyright if you do 444 | not accept this License. Therefore, by modifying or propagating a 445 | covered work, you indicate your acceptance of this License to do so. 446 | 447 | 10. Automatic Licensing of Downstream Recipients. 448 | 449 | Each time you convey a covered work, the recipient automatically 450 | receives a license from the original licensors, to run, modify and 451 | propagate that work, subject to this License. You are not responsible 452 | for enforcing compliance by third parties with this License. 453 | 454 | An "entity transaction" is a transaction transferring control of an 455 | organization, or substantially all assets of one, or subdividing an 456 | organization, or merging organizations. If propagation of a covered 457 | work results from an entity transaction, each party to that 458 | transaction who receives a copy of the work also receives whatever 459 | licenses to the work the party's predecessor in interest had or could 460 | give under the previous paragraph, plus a right to possession of the 461 | Corresponding Source of the work from the predecessor in interest, if 462 | the predecessor has it or can get it with reasonable efforts. 463 | 464 | You may not impose any further restrictions on the exercise of the 465 | rights granted or affirmed under this License. For example, you may 466 | not impose a license fee, royalty, or other charge for exercise of 467 | rights granted under this License, and you may not initiate litigation 468 | (including a cross-claim or counterclaim in a lawsuit) alleging that 469 | any patent claim is infringed by making, using, selling, offering for 470 | sale, or importing the Program or any portion of it. 471 | 472 | 11. Patents. 473 | 474 | A "contributor" is a copyright holder who authorizes use under this 475 | License of the Program or a work on which the Program is based. The 476 | work thus licensed is called the contributor's "contributor version". 477 | 478 | A contributor's "essential patent claims" are all patent claims 479 | owned or controlled by the contributor, whether already acquired or 480 | hereafter acquired, that would be infringed by some manner, permitted 481 | by this License, of making, using, or selling its contributor version, 482 | but do not include claims that would be infringed only as a 483 | consequence of further modification of the contributor version. For 484 | purposes of this definition, "control" includes the right to grant 485 | patent sublicenses in a manner consistent with the requirements of 486 | this License. 487 | 488 | Each contributor grants you a non-exclusive, worldwide, royalty-free 489 | patent license under the contributor's essential patent claims, to 490 | make, use, sell, offer for sale, import and otherwise run, modify and 491 | propagate the contents of its contributor version. 492 | 493 | In the following three paragraphs, a "patent license" is any express 494 | agreement or commitment, however denominated, not to enforce a patent 495 | (such as an express permission to practice a patent or covenant not to 496 | sue for patent infringement). To "grant" such a patent license to a 497 | party means to make such an agreement or commitment not to enforce a 498 | patent against the party. 499 | 500 | If you convey a covered work, knowingly relying on a patent license, 501 | and the Corresponding Source of the work is not available for anyone 502 | to copy, free of charge and under the terms of this License, through a 503 | publicly available network server or other readily accessible means, 504 | then you must either (1) cause the Corresponding Source to be so 505 | available, or (2) arrange to deprive yourself of the benefit of the 506 | patent license for this particular work, or (3) arrange, in a manner 507 | consistent with the requirements of this License, to extend the patent 508 | license to downstream recipients. "Knowingly relying" means you have 509 | actual knowledge that, but for the patent license, your conveying the 510 | covered work in a country, or your recipient's use of the covered work 511 | in a country, would infringe one or more identifiable patents in that 512 | country that you have reason to believe are valid. 513 | 514 | If, pursuant to or in connection with a single transaction or 515 | arrangement, you convey, or propagate by procuring conveyance of, a 516 | covered work, and grant a patent license to some of the parties 517 | receiving the covered work authorizing them to use, propagate, modify 518 | or convey a specific copy of the covered work, then the patent license 519 | you grant is automatically extended to all recipients of the covered 520 | work and works based on it. 521 | 522 | A patent license is "discriminatory" if it does not include within 523 | the scope of its coverage, prohibits the exercise of, or is 524 | conditioned on the non-exercise of one or more of the rights that are 525 | specifically granted under this License. You may not convey a covered 526 | work if you are a party to an arrangement with a third party that is 527 | in the business of distributing software, under which you make payment 528 | to the third party based on the extent of your activity of conveying 529 | the work, and under which the third party grants, to any of the 530 | parties who would receive the covered work from you, a discriminatory 531 | patent license (a) in connection with copies of the covered work 532 | conveyed by you (or copies made from those copies), or (b) primarily 533 | for and in connection with specific products or compilations that 534 | contain the covered work, unless you entered into that arrangement, 535 | or that patent license was granted, prior to 28 March 2007. 536 | 537 | Nothing in this License shall be construed as excluding or limiting 538 | any implied license or other defenses to infringement that may 539 | otherwise be available to you under applicable patent law. 540 | 541 | 12. No Surrender of Others' Freedom. 542 | 543 | If conditions are imposed on you (whether by court order, agreement or 544 | otherwise) that contradict the conditions of this License, they do not 545 | excuse you from the conditions of this License. If you cannot convey a 546 | covered work so as to satisfy simultaneously your obligations under this 547 | License and any other pertinent obligations, then as a consequence you may 548 | not convey it at all. For example, if you agree to terms that obligate you 549 | to collect a royalty for further conveying from those to whom you convey 550 | the Program, the only way you could satisfy both those terms and this 551 | License would be to refrain entirely from conveying the Program. 552 | 553 | 13. Use with the GNU Affero General Public License. 554 | 555 | Notwithstanding any other provision of this License, you have 556 | permission to link or combine any covered work with a work licensed 557 | under version 3 of the GNU Affero General Public License into a single 558 | combined work, and to convey the resulting work. The terms of this 559 | License will continue to apply to the part which is the covered work, 560 | but the special requirements of the GNU Affero General Public License, 561 | section 13, concerning interaction through a network will apply to the 562 | combination as such. 563 | 564 | 14. Revised Versions of this License. 565 | 566 | The Free Software Foundation may publish revised and/or new versions of 567 | the GNU General Public License from time to time. Such new versions will 568 | be similar in spirit to the present version, but may differ in detail to 569 | address new problems or concerns. 570 | 571 | Each version is given a distinguishing version number. If the 572 | Program specifies that a certain numbered version of the GNU General 573 | Public License "or any later version" applies to it, you have the 574 | option of following the terms and conditions either of that numbered 575 | version or of any later version published by the Free Software 576 | Foundation. If the Program does not specify a version number of the 577 | GNU General Public License, you may choose any version ever published 578 | by the Free Software Foundation. 579 | 580 | If the Program specifies that a proxy can decide which future 581 | versions of the GNU General Public License can be used, that proxy's 582 | public statement of acceptance of a version permanently authorizes you 583 | to choose that version for the Program. 584 | 585 | Later license versions may give you additional or different 586 | permissions. However, no additional obligations are imposed on any 587 | author or copyright holder as a result of your choosing to follow a 588 | later version. 589 | 590 | 15. Disclaimer of Warranty. 591 | 592 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 593 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 594 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 595 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 596 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 597 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 598 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 599 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 600 | 601 | 16. Limitation of Liability. 602 | 603 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 604 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 605 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 606 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 607 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 608 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 609 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 610 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 611 | SUCH DAMAGES. 612 | 613 | 17. Interpretation of Sections 15 and 16. 614 | 615 | If the disclaimer of warranty and limitation of liability provided 616 | above cannot be given local legal effect according to their terms, 617 | reviewing courts shall apply local law that most closely approximates 618 | an absolute waiver of all civil liability in connection with the 619 | Program, unless a warranty or assumption of liability accompanies a 620 | copy of the Program in return for a fee. 621 | 622 | END OF TERMS AND CONDITIONS 623 | 624 | How to Apply These Terms to Your New Programs 625 | 626 | If you develop a new program, and you want it to be of the greatest 627 | possible use to the public, the best way to achieve this is to make it 628 | free software which everyone can redistribute and change under these terms. 629 | 630 | To do so, attach the following notices to the program. It is safest 631 | to attach them to the start of each source file to most effectively 632 | state the exclusion of warranty; and each file should have at least 633 | the "copyright" line and a pointer to where the full notice is found. 634 | 635 | {one line to give the program's name and a brief idea of what it does.} 636 | Copyright (C) {year} {name of author} 637 | 638 | This program is free software: you can redistribute it and/or modify 639 | it under the terms of the GNU General Public License as published by 640 | the Free Software Foundation, either version 3 of the License, or 641 | (at your option) any later version. 642 | 643 | This program is distributed in the hope that it will be useful, 644 | but WITHOUT ANY WARRANTY; without even the implied warranty of 645 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 646 | GNU General Public License for more details. 647 | 648 | You should have received a copy of the GNU General Public License 649 | along with this program. If not, see [http://www.gnu.org/licenses/]. 650 | 651 | Also add information on how to contact you by electronic and paper mail. 652 | 653 | If the program does terminal interaction, make it output a short 654 | notice like this when it starts in an interactive mode: 655 | 656 | {project} Copyright (C) {year} {fullname} 657 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 658 | This is free software, and you are welcome to redistribute it 659 | under certain conditions; type `show c' for details. 660 | 661 | The hypothetical commands `show w' and `show c' should show the appropriate 662 | parts of the General Public License. Of course, your program's commands 663 | might be different; for a GUI interface, you would use an "about box". 664 | 665 | You should also get your employer (if you work as a programmer) or school, 666 | if any, to sign a "copyright disclaimer" for the program, if necessary. 667 | For more information on this, and how to apply and follow the GNU GPL, see 668 | [http://www.gnu.org/licenses/]. 669 | 670 | The GNU General Public License does not permit incorporating your program 671 | into proprietary programs. If your program is a subroutine library, you 672 | may consider it more useful to permit linking proprietary applications with 673 | the library. If this is what you want to do, use the GNU Lesser General 674 | Public License instead of this License. But first, please read 675 | [http://www.gnu.org/philosophy/why-not-lgpl.html]. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Joomlatools Composer Installer 2 | 3 | This Composer plugin will install extensions into your Joomla setup. 4 | 5 | ## Usage 6 | 7 | ### Defining a package 8 | 9 | The easiest way to get started is by defining a custom package in your `composer.json` file. All you need is the package file for the extension you wish to install. (ie. the installer file you downloaded from the vendor's website) 10 | 11 | Update the `composer.json` file in the root directory of your Joomla installation by adding the following properties: 12 | 13 | ```json 14 | { 15 | "repositories": [ 16 | { 17 | "type": "package", 18 | "package": { 19 | "name": "vendor/extension", 20 | "type": "joomlatools-extension", 21 | "version": "1.0.0", 22 | "dist": { 23 | "url": "file:////Users/johndoe/Downloads/com_extension.1.0.0.tar.gz", 24 | "type": "tar" 25 | }, 26 | "require": { 27 | "joomlatools/composer": "*" 28 | } 29 | } 30 | } 31 | ], 32 | 33 | ... 34 | 35 | "require": { 36 | ... 37 | "vendor/extension": "1.0.0" 38 | } 39 | } 40 | ``` 41 | 42 | Using this JSON file, we have now defined our own custom package. Pay attention to the following settings: 43 | 44 | * The `type` has to be set to `joomlatools-extension` 45 | * Make sure the `url` directive points to the location of the install package. 46 | 47 | Executing `composer install` will now fetch the `joomlatools/composer` plugin and use it to install the package into your Joomla installation. 48 | 49 | For more information on creating these custom packages for projects which do not support Composer, see the [Composer docs](http://getcomposer.org/doc/05-repositories.md#package-2). 50 | 51 | ### Creating a custom package 52 | 53 | To make use of all Composer's features, eg. upgrading to a newer version, you are better off creating a package using your extension's source code. 54 | 55 | The package definition should contain the following basic information to make it installable into Joomla: 56 | 57 | ```json 58 | { 59 | "name": "vendor/my-extension", 60 | "type": "joomlatools-extension", 61 | "require": { 62 | "joomlatools/composer": "*" 63 | } 64 | } 65 | ``` 66 | 67 | If you want to make your extension available directly from Github or any other VCS, you want to make sure that the file layout in your repo resembles your install package. 68 | 69 | If you want to move the main Joomla installer manifest to the repository root before running the installation, provide the following information in your `composer.json`file: 70 | 71 | ```json 72 | { 73 | "extra": { 74 | "manifest": "path/to/manifest/joomlatools.xml" 75 | } 76 | } 77 | ``` 78 | 79 | If the package is for a Joomlatools Framework reusable component, provide the following information in your `composer.json`file: 80 | 81 | ```json 82 | { 83 | "extra": { 84 | "joomlatools-component": "component-name" 85 | } 86 | } 87 | ``` 88 | 89 | You can now publish your extension on [Packagist](https://packagist.org/) or serve it yourself using your own [Satis repository](http://getcomposer.org/doc/articles/handling-private-packages-with-satis.md). 90 | 91 | For more information on rolling your own package, please refer to the [Composer documentation](http://getcomposer.org/doc/02-libraries.md). 92 | 93 | ### More 94 | 95 | For more information, FAQ and examples, refer to our [developer documentation](https://www.joomlatools.com/developer/tools/composer/). 96 | 97 | ## Development 98 | 99 | Refer to [the wiki](https://github.com/joomlatools/joomlatools-composer/wiki#development-set-up) on how to set up this repository for local development. 100 | 101 | ## Debugging 102 | 103 | Having trouble? You can increase Composer's verbosity setting (`-v|vv|vvv`) to gather more information. Increasing Composer's verbosity will also enable Joomla's log messages. 104 | 105 | ## Requirements 106 | 107 | * Composer 108 | * Joomla version 3.6+ 109 | 110 | ## Contributing 111 | 112 | The `joomlatools/composer` plugin is an open source, community-driven project. Contributions are welcome from everyone. We have [contributing guidelines](CONTRIBUTING.md) to help you get started. 113 | 114 | ## Contributors 115 | 116 | See the list of [contributors](https://github.com/joomlatools/joomlatools-composer/contributors). 117 | 118 | ## License 119 | 120 | The `joomlatools/composer` plugin is free and open-source software licensed under the [GPLv3 license](LICENSE.txt). 121 | 122 | ## Community 123 | 124 | Keep track of development and community news. 125 | 126 | * Follow [@joomlatoolsdev on Twitter](https://twitter.com/joomlatoolsdev) 127 | * Join [joomlatools/dev on Gitter](http://gitter.im/joomlatools/dev) 128 | * Read the [Joomlatools Developer Blog](https://www.joomlatools.com/developer/blog/) 129 | * Subscribe to the [Joomlatools Developer Newsletter](https://www.joomlatools.com/developer/newsletter/) 130 | 131 | [gplv3-license]: https://github.com/nooku/nooku-framework/blob/master/LICENSE.txt 132 | -------------------------------------------------------------------------------- /_travis/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo "** Installing joomlatools/console" 6 | composer global require --no-interaction joomlatools/console 7 | 8 | composer global exec joomla -V 9 | -------------------------------------------------------------------------------- /_travis/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | FILE="$DOCUMENTROOT/testsite/administrator/components/com_helloworld/helloworld.php" 6 | DB="sites_testsite.j_extensions" 7 | 8 | if [[ "$REPO" == *"joomlatools/joomlatools-platform"* ]]; then 9 | FILE="$DOCUMENTROOT/testsite/app/administrator/components/com_helloworld/helloworld.php" 10 | DB="sites_testsite.extensions" 11 | fi 12 | 13 | echo "** Installing test extension" 14 | composer require -vv --working-dir=$DOCUMENTROOT/testsite --no-interaction joomlatools/composer-helloworld:dev-testbranch 15 | 16 | # Verify if component file is present 17 | echo "** Looking for helloworld.php" 18 | 19 | echo "** Verifying helloworld.php contents" 20 | if [ ! -f $FILE ]; then 21 | echo "$FILE does not exist" 22 | exit 1 23 | fi 24 | 25 | if ! grep -q "echo 'Hello World\!'" $FILE; then 26 | echo "$FILE does not contain string" 27 | exit 1 28 | fi 29 | 30 | # Test if the row exists in the database 31 | echo "** Verifying extensions row in database" 32 | 33 | COUNT=$(mysql -uroot -s -N -e "SELECT COUNT(extension_id) FROM $DB WHERE element = 'com_helloworld';") 34 | echo "Matched $COUNT rows" 35 | 36 | if [ $COUNT -le 0 ]; then 37 | exit 1 38 | fi 39 | -------------------------------------------------------------------------------- /_travis/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo "** Configuring PHP" 6 | phpenv config-rm xdebug.ini 7 | echo 'error_reporting = 22519' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini 8 | 9 | echo "** Create documentroot directory" 10 | mkdir -p $DOCUMENTROOT 11 | 12 | echo "** Checkout test branch" 13 | git checkout -b testbranch 14 | git commit -a -m "Commit PR changes" 15 | 16 | # Based on the instructions from https://github.com/joomlatools/joomlatools-composer/wiki 17 | echo "** Set up joomlatools/composer-helloworld" 18 | git clone https://github.com/joomlatools/joomlatools-composer-helloworld.git /tmp/joomlatools-composer-helloworld/ 19 | 20 | cd /tmp/joomlatools-composer-helloworld/ 21 | git checkout -b testbranch 22 | cat >/tmp/joomlatools-composer-helloworld/composer.json < 7 | * @link http://github.com/joomlatools/joomlatools-composer for the canonical source repository 8 | */ 9 | 10 | namespace Joomlatools\Composer; 11 | 12 | use Composer\Package\PackageInterface; 13 | use Composer\Repository\InstalledRepositoryInterface; 14 | use Composer\Installer\LibraryInstaller; 15 | 16 | use Joomlatools\Joomla\Bootstrapper; 17 | use Joomlatools\Joomla\Util; 18 | 19 | /** 20 | * Composer installer class 21 | * 22 | * @author Steven Rombauts 23 | * @package Joomlatools\Composer 24 | */ 25 | class ComposerInstaller extends LibraryInstaller 26 | { 27 | /** 28 | * {@inheritDoc} 29 | */ 30 | public function install(InstalledRepositoryInterface $repo, PackageInterface $package) 31 | { 32 | $platformStr = Util::isJoomlatoolsPlatform() ? 'Joomlatools Platform' : 'Joomla'; 33 | $afterInstall = function () use ($package, $platformStr) { 34 | if ($this->io->isVerbose()) { 35 | $this->io->write(sprintf(" - Queuing %s for installation in %s", $package->getName(), $platformStr), true); 36 | } 37 | 38 | TaskQueue::getInstance()->enqueue(array('install', $package, $this->getInstallPath($package))); 39 | }; 40 | 41 | $promise = parent::install($repo, $package); 42 | 43 | // Composer v2 might return a promise here 44 | if ($promise instanceof \React\Promise\PromiseInterface) { 45 | return $promise->then($afterInstall); 46 | } 47 | 48 | $afterInstall(); 49 | } 50 | 51 | /** 52 | * {@inheritDoc} 53 | */ 54 | public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) 55 | { 56 | $platformStr = Util::isJoomlatoolsPlatform() ? 'Joomlatools Platform' : 'Joomla'; 57 | $afterUpdate = function () use ($target, $platformStr) { 58 | if ($this->io->isVerbose()) { 59 | $this->io->write(sprintf(" - Queuing %s for upgrading in %s", $target->getName(), $platformStr), true); 60 | } 61 | 62 | TaskQueue::getInstance()->enqueue(array('update', $target, $this->getInstallPath($target))); 63 | }; 64 | 65 | $promise = parent::update($repo, $initial, $target); 66 | 67 | // Composer v2 might return a promise here 68 | if ($promise instanceof \React\Promise\PromiseInterface) { 69 | return $promise->then($afterUpdate); 70 | } 71 | 72 | $afterUpdate(); 73 | 74 | } 75 | 76 | /** 77 | * {@inheritDoc} 78 | */ 79 | public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) 80 | { 81 | if (!$repo->hasPackage($package)) { 82 | throw new \InvalidArgumentException('Package is not installed: '.$package); 83 | } 84 | 85 | $platformStr = Util::isJoomlatoolsPlatform() ? 'Joomlatools Platform' : 'Joomla'; 86 | $afterUninstall = function () use ($package, $platformStr) { 87 | if ($this->io->isVerbose()) { 88 | $this->io->write(sprintf(" - Queuing %s for upgrading in %s", $target->getName(), $platformStr), true); 89 | } 90 | 91 | TaskQueue::getInstance()->enqueue(array('update', $target, $this->getInstallPath($target))); 92 | }; 93 | 94 | if ($this->io->isVerbose()) { 95 | $this->io->write(sprintf(" - Queuing %s for removal from %s", $package->getName(), $platformStr), true); 96 | } 97 | 98 | TaskQueue::getInstance()->enqueue(array('uninstall', $package, $this->getInstallPath($package))); 99 | 100 | if (Util::isReusableComponent($package)) { 101 | parent::uninstall($repo, $package); 102 | } else { 103 | // Find the manifest and set it aside so we can query it when actually uninstalling the extension 104 | $installPath = $this->getInstallPath($package); 105 | $manifest = Util::getPackageManifest($installPath); 106 | $prefix = str_replace(DIRECTORY_SEPARATOR, '-', $package->getName()); 107 | $tmpFile = tempnam(sys_get_temp_dir(), $prefix); 108 | 109 | if (copy($manifest, $tmpFile)) 110 | { 111 | Util::setPackageManifest($installPath, $tmpFile); 112 | 113 | parent::uninstall($repo, $package); 114 | } 115 | else 116 | { 117 | if ($this->io->isVerbose()) { 118 | $this->io->write(sprintf(" [ERROR] Could not copy manifest %s to %s. Skipping uninstall of %s.", $manifest, $tmpFile, $package->getName()), true); 119 | } 120 | } 121 | } 122 | 123 | } 124 | 125 | /** 126 | * {@inheritDoc} 127 | */ 128 | public function supports($packageType) 129 | { 130 | return in_array($packageType, array('joomlatools-composer', 'joomlatools-extension', 'joomlatools-installer', 'joomla-installer')); 131 | } 132 | 133 | /** 134 | * {@inheritDoc} 135 | */ 136 | public function isInstalled(InstalledRepositoryInterface $repo, PackageInterface $package) 137 | { 138 | if (Util::isReusableComponent($package)) { 139 | return true; // If Composer didn't error out, we can conclude it is installed 140 | } 141 | 142 | $application = Bootstrapper::getInstance()->getApplication(); 143 | 144 | if ($application === false) 145 | { 146 | if ($this->io->isVerbose()) { 147 | $this->io->write(sprintf("Warning: Can not instantiate application to check if %s is installed", $package->getName()), true); 148 | } 149 | 150 | return false; 151 | } 152 | 153 | $installPath = $this->getInstallPath($package); 154 | 155 | return $application->isInstalled($installPath); 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/Joomlatools/Composer/ExtensionInstaller.php: -------------------------------------------------------------------------------- 1 | 7 | * @link http://github.com/joomlatools/joomlatools-composer for the canonical source repository 8 | */ 9 | 10 | namespace Joomlatools\Composer; 11 | 12 | use Joomlatools\Joomla\Bootstrapper; 13 | use Joomlatools\Joomla\Util; 14 | 15 | use Composer\IO\IOInterface; 16 | use Composer\Package\PackageInterface; 17 | 18 | /** 19 | * Joomla extension installer class 20 | * 21 | * @author Steven Rombauts 22 | * @package Joomlatools\Composer 23 | */ 24 | class ExtensionInstaller 25 | { 26 | /** @var IOInterface $io */ 27 | protected $_io = null; 28 | 29 | public function __construct(IOInterface $io) 30 | { 31 | $this->_io = $io; 32 | } 33 | 34 | public function execute() 35 | { 36 | if (!Util::isJoomla() && !Util::isJoomlatoolsPlatform() && !Util::isJoomla4()) { 37 | return true; 38 | } 39 | 40 | $application = Bootstrapper::getInstance()->getApplication(); 41 | 42 | if ($application === false) 43 | { 44 | $this->_io->write(sprintf('[ERROR] Failed to initialize the %1$s application! %1$s extensions will not be installed or removed. Is the application properly configured?', Util::getPlatformName())); 45 | 46 | return; 47 | } 48 | 49 | foreach (TaskQueue::getInstance() as $task) 50 | { 51 | list($action, $package, $installPath) = $task; 52 | 53 | if (method_exists($this, $action)) { 54 | call_user_func_array(array($this, $action), array($package, $installPath)); 55 | } 56 | } 57 | } 58 | 59 | public function install(PackageInterface $package, $installPath) 60 | { 61 | $application = Bootstrapper::getInstance()->getApplication(); 62 | 63 | if (Util::isReusableComponent($package)) { 64 | return $this->_installReusableComponent($package, $installPath); 65 | } 66 | 67 | $this->_copyManifestFiles($package, $installPath); 68 | 69 | $this->_io->write(sprintf("Installing the %s extension %s %s", Util::getPlatformName(), $package->getName(), $package->getFullPrettyVersion())); 70 | 71 | if(!$application->install($installPath)) 72 | { 73 | // Get all error messages that were stored in the message queue 74 | $descriptions = $this->_getApplicationMessages(); 75 | 76 | $error = 'Error while installing '.$package->getPrettyName(); 77 | if(count($descriptions)) { 78 | $error .= ':'.PHP_EOL.implode(PHP_EOL, $descriptions); 79 | } 80 | 81 | throw new \RuntimeException($error); 82 | } 83 | 84 | $this->_enablePlugin($package, $installPath); 85 | } 86 | 87 | public function update(PackageInterface $package, $installPath) 88 | { 89 | if (Util::isReusableComponent($package)) { 90 | return $this->_installReusableComponent($package, $installPath); 91 | } 92 | 93 | $this->_copyManifestFiles($package, $installPath); 94 | 95 | $this->_io->write(sprintf("Updating the %s extension %s to %s", Util::getPlatformName(), $package->getName(), $package->getFullPrettyVersion())); 96 | 97 | if(!Bootstrapper::getInstance()->getApplication()->update($installPath)) 98 | { 99 | 100 | // Get all error messages that were stored in the message queue 101 | $descriptions = $this->_getApplicationMessages(); 102 | 103 | $error = 'Error while updating '.$package->getPrettyName(); 104 | if(count($descriptions)) { 105 | $error .= ':'.PHP_EOL.implode(PHP_EOL, $descriptions); 106 | } 107 | 108 | throw new \RuntimeException($error); 109 | } 110 | } 111 | 112 | /** 113 | * {@inheritDoc} 114 | */ 115 | public function uninstall(PackageInterface $package, $installPath) 116 | { 117 | if (Util::isReusableComponent($package)) { 118 | return $this->_uninstallReusableComponent($package, $installPath); 119 | } 120 | 121 | $file = Util::getPackageManifest($installPath); 122 | 123 | if($file !== false && file_exists($file)) 124 | { 125 | $this->_io->write(sprintf("Uninstalling the %s extension %s", Util::getPlatformName(), $package->getName())); 126 | 127 | $manifest = simplexml_load_file($file); 128 | 129 | $type = (string) $manifest->attributes()->type; 130 | $element = Util::getNameFromManifest($installPath); 131 | 132 | if (!empty($element)) 133 | { 134 | $application = Bootstrapper::getInstance()->getApplication(); 135 | $extension = $application->getExtension($element, $type); 136 | 137 | if ($extension) { 138 | $application->uninstall($extension->id, $type); 139 | } 140 | } 141 | } 142 | else $this->_io->write(sprintf("[WARNING] Can not uninstall the %s extension %s: XML manifest not found.", Util::getPlatformName(), $package->getName())); 143 | } 144 | 145 | protected function _installReusableComponent(PackageInterface $package, $installPath) 146 | { 147 | Bootstrapper::getInstance()->getApplication(); // required to load Joomla libs 148 | 149 | \jimport('joomla.filesystem.folder'); 150 | \jimport('joomla.filesystem.file'); 151 | 152 | $this->_io->write(sprintf("Installing the %s reusable component %s %s", Util::getPlatformName(), $package->getName(), $package->getFullPrettyVersion())); 153 | 154 | $extra = $package->getExtra(); 155 | $name = $extra['joomlatools-component']; 156 | $map = array( 157 | $installPath => JPATH_LIBRARIES.'/joomlatools-components/'.$name, 158 | $installPath.'/resources/assets' => (Util::isJoomlatoolsPlatform() ? JPATH_WEB : JPATH_ROOT) . '/media/koowa/com_'.$name 159 | ); 160 | 161 | foreach ($map as $from => $to) 162 | { 163 | $temp = $to.'_tmp'; 164 | 165 | if (!is_dir($from)) { 166 | continue; 167 | } 168 | 169 | if (is_dir($temp)) { 170 | \JFolder::delete($temp); 171 | } 172 | 173 | \JFolder::copy($from, $temp); 174 | 175 | if (is_dir($to)) { 176 | \JFolder::delete($to); 177 | } 178 | 179 | \JFolder::move($temp, $to); 180 | } 181 | 182 | $install_sql = JPATH_LIBRARIES.'/joomlatools-components/'.$name.'/resources/install/install.sql'; 183 | if (is_file($install_sql)) { 184 | $db = \JFactory::getDbo(); 185 | $queries = $db->splitSql(file_get_contents($install_sql)); 186 | 187 | if ($queries) { 188 | foreach ($queries as $query) { 189 | $query = trim($query); 190 | 191 | if ($query != '' && $query[0] != '#') { 192 | try { 193 | $db->setQuery($query)->execute(); 194 | } catch (\Exception $e) { 195 | } 196 | } 197 | } 198 | } 199 | } 200 | } 201 | 202 | protected function _uninstallReusableComponent(PackageInterface $package, $installPath) 203 | { 204 | Bootstrapper::getInstance()->getApplication(); // required to load Joomla libs 205 | 206 | \jimport('joomla.filesystem.folder'); 207 | \jimport('joomla.filesystem.file'); 208 | 209 | $this->_io->write(sprintf("Uninstalling the %s reusable component %s %s", Util::getPlatformName(), $package->getName(), $package->getFullPrettyVersion())); 210 | 211 | $name = $package->getExtra()['joomlatools-component']; 212 | $folders = array( 213 | JPATH_LIBRARIES.'/joomlatools-components/'.$name, 214 | (Util::isJoomlatoolsPlatform() ? JPATH_WEB : JPATH_ROOT) . '/media/koowa/com_'.$name 215 | ); 216 | 217 | foreach ($folders as $folder) 218 | { 219 | if (is_dir($folder)) { 220 | \JFolder::delete($folder); 221 | } 222 | } 223 | } 224 | 225 | protected function _copyManifestFiles(PackageInterface $package, $installPath) 226 | { 227 | $extra = $package->getExtra(); 228 | 229 | if (is_array($extra) && isset($extra['manifest'])) 230 | { 231 | $manifest_name = basename($extra['manifest']); 232 | $manifest_dir = $installPath.'/'.dirname($extra['manifest']); 233 | $target_dir = is_dir($installPath.'/code') ? $installPath.'/code' : $installPath; 234 | 235 | copy($manifest_dir.'/'.$manifest_name, $target_dir.'/'.$manifest_name); 236 | 237 | if (is_file($manifest_dir.'/script.php')) { 238 | copy($manifest_dir.'/script.php', $target_dir.'/script.php'); 239 | } 240 | } 241 | } 242 | 243 | /** 244 | * Fetches the enqueued flash messages from the Joomla application object. 245 | * 246 | * @return array 247 | */ 248 | protected function _getApplicationMessages() 249 | { 250 | $messages = Bootstrapper::getInstance()->getApplication()->getMessageQueue(); 251 | $descriptions = array(); 252 | 253 | foreach($messages as $message) 254 | { 255 | if($message['type'] == 'error') { 256 | $descriptions[] = $message['message']; 257 | } 258 | } 259 | 260 | return $descriptions; 261 | } 262 | 263 | /** 264 | * Enable all plugins that were installed with this package. 265 | * 266 | * @param PackageInterface $package 267 | * @param string $subdirectory Subdirectory in package install path to look for plugin manifests 268 | */ 269 | protected function _enablePlugin(PackageInterface $package, $installPath, $subdirectory = '') 270 | { 271 | $path = realpath($installPath . '/' . $subdirectory); 272 | $file = Util::getPackageManifest($path); 273 | 274 | if($file !== false) 275 | { 276 | $manifest = simplexml_load_file($file); 277 | $type = (string) $manifest->attributes()->type; 278 | 279 | if ($type == 'plugin') 280 | { 281 | $name = Util::getNameFromManifest($installPath); 282 | $group = (string) $manifest->attributes()->group; 283 | 284 | $extension = Bootstrapper::getInstance()->getApplication()->getExtension($name, 'plugin', $group); 285 | 286 | if (is_object($extension) && $extension->id > 0) 287 | { 288 | $sql = "UPDATE `#__extensions`" 289 | ." SET `enabled` = 1" 290 | ." WHERE `extension_id` = ".$extension->id; 291 | 292 | \JFactory::getDbo()->setQuery($sql)->execute(); 293 | } 294 | } 295 | elseif ($type == 'package') 296 | { 297 | foreach($manifest->files->children() as $file) 298 | { 299 | if ((string) $file->attributes()->type == 'plugin') { 300 | $this->_enablePlugin($package, $installPath, (string) $file); 301 | } 302 | } 303 | } 304 | } 305 | } 306 | } 307 | -------------------------------------------------------------------------------- /src/Joomlatools/Composer/Plugin.php: -------------------------------------------------------------------------------- 1 | 7 | * @link http://github.com/joomlatools/joomlatools-composer for the canonical source repository 8 | */ 9 | 10 | namespace Joomlatools\Composer; 11 | 12 | use Joomlatools\Joomla\Bootstrapper; 13 | use Joomlatools\Joomla\Util; 14 | 15 | use Composer\Composer; 16 | use Composer\EventDispatcher\EventSubscriberInterface; 17 | use Composer\IO\IOInterface; 18 | use Composer\Plugin\PluginInterface; 19 | use Composer\Script\Event; 20 | use Composer\Script\ScriptEvents; 21 | 22 | /** 23 | * Composer plugin class 24 | * 25 | * @author Steven Rombauts 26 | * @package Joomlatools\Composer 27 | */ 28 | class Plugin implements PluginInterface, EventSubscriberInterface 29 | { 30 | /** @var Composer $composer */ 31 | protected $_composer; 32 | /** @var IOInterface $io */ 33 | protected $_io; 34 | 35 | /** 36 | * Apply plugin modifications to composer 37 | * 38 | * @param Composer $composer 39 | * @param IOInterface $io 40 | */ 41 | public function activate(Composer $composer, IOInterface $io) 42 | { 43 | $this->_composer = $composer; 44 | $this->_io = $io; 45 | 46 | if (!Util::isJoomla() && !Util::isJoomlatoolsPlatform() && !Util::isJoomla4()) { 47 | return true; 48 | } 49 | 50 | $credentials = $this->_composer->getConfig()->get('joomla'); 51 | 52 | if(is_null($credentials) || !is_array($credentials)) { 53 | $credentials = array(); 54 | } 55 | 56 | $bootstrapper = Bootstrapper::getInstance(); 57 | $bootstrapper->setIO($this->_io); 58 | $bootstrapper->setCredentials($credentials); 59 | 60 | $installer = new ComposerInstaller($this->_io, $this->_composer); 61 | $composer->getInstallationManager()->addInstaller($installer); 62 | } 63 | 64 | public function deactivate(Composer $composer, IOInterface $io) {} 65 | 66 | /** 67 | * Prepare the plugin to be uninstalled 68 | * 69 | * This will be called after deactivate. 70 | * 71 | * @param Composer $composer 72 | * @param IOInterface $io 73 | */ 74 | public function uninstall(Composer $composer, IOInterface $io) {} 75 | 76 | public static function getSubscribedEvents() 77 | { 78 | return array( 79 | ScriptEvents::POST_AUTOLOAD_DUMP => 'postAutoloadDump' 80 | ); 81 | } 82 | 83 | public function postAutoloadDump(Event $event) 84 | { 85 | $extensionInstaller = new ExtensionInstaller($this->_io); 86 | $extensionInstaller->execute(); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/Joomlatools/Composer/TaskQueue.php: -------------------------------------------------------------------------------- 1 | 7 | * @link http://github.com/joomlatools/joomlatools-composer for the canonical source repository 8 | */ 9 | 10 | namespace Joomlatools\Composer; 11 | 12 | use SplQueue; 13 | 14 | /** 15 | * Task queue class 16 | * 17 | * @author Steven Rombauts 18 | * @package Joomlatools\Composer 19 | */ 20 | class TaskQueue extends SplQueue 21 | { 22 | private static $__instance = null; 23 | 24 | public function __construct() 25 | { 26 | $this->setIteratorMode(SplQueue::IT_MODE_DELETE); 27 | } 28 | 29 | /** 30 | * Get instance of this class 31 | * 32 | * @return TaskQueue $instance 33 | */ 34 | public static function getInstance() 35 | { 36 | if (!self::$__instance) { 37 | self::$__instance = new TaskQueue(); 38 | } 39 | 40 | return self::$__instance; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Joomlatools/Joomla/Application.php: -------------------------------------------------------------------------------- 1 | 7 | * @link http://github.com/joomlatools/joomlatools-composer for the canonical source repository 8 | */ 9 | 10 | namespace Joomlatools\Joomla; 11 | 12 | use Composer\Package\PackageInterface; 13 | 14 | use Symfony\Component\Console\Output\OutputInterface; 15 | 16 | use \JApplicationCli as JApplicationCli; 17 | use \JDispatcher as JDispatcher; 18 | use \JFactory as JFactory; 19 | use \JInstaller as JInstaller; 20 | use \JSession as JSession; 21 | use \JRouter as JRouter; 22 | use \JVersion as JVersion; 23 | use \JLog as JLog; 24 | 25 | /** 26 | * Application extending Joomla CLI class. 27 | * 28 | * @author Steven Rombauts 29 | * @package Joomlatools\Composer 30 | */ 31 | class Application extends JApplicationCli 32 | { 33 | protected $_messageQueue = array(); 34 | protected $_options = array(); 35 | protected $_is_platform = false; 36 | 37 | /** 38 | * Class constructor. 39 | * 40 | * @param array $options An array of configuration settings. 41 | * @param mixed $input An optional argument to provide dependency injection for the application's 42 | * input object. 43 | * @param mixed $config An optional argument to provide dependency injection for the application's 44 | * config object. 45 | * @param mixed $dispatcher An optional argument to provide dependency injection for the application's 46 | * event dispatcher. 47 | * @return void 48 | * 49 | * @see JApplicationCli 50 | */ 51 | public function __construct($options = array(), JInputCli $input = null, JRegistry $config = null, JDispatcher $dispatcher = null) 52 | { 53 | $this->_options = $options; 54 | 55 | if (isset($this->_options['platform'])) { 56 | $this->_is_platform = $this->_options['platform']; 57 | } 58 | 59 | if (isset($this->_options['loglevel'])) { 60 | $this->_setupLogging($this->_options['loglevel']); 61 | } 62 | 63 | parent::__construct($input, $config, $dispatcher); 64 | 65 | $this->_initialize(); 66 | } 67 | 68 | /** 69 | * Initialise the application. 70 | * 71 | * Loads the necessary Joomla libraries to make sure 72 | * the Joomla application can run and sets up the JFactory properties. 73 | * 74 | * @param array $options An optional associative array of configuration settings. 75 | * @return void 76 | */ 77 | protected function _initialize() 78 | { 79 | // Load dependencies 80 | jimport('joomla.application.component.helper'); 81 | jimport('joomla.application.menu'); 82 | 83 | jimport('joomla.environment.uri'); 84 | 85 | jimport('joomla.event.dispatcher'); 86 | 87 | jimport('joomla.utilities.utility'); 88 | jimport('joomla.utilities.arrayhelper'); 89 | 90 | jimport('joomla.application.module.helper'); 91 | 92 | jimport('joomla.filesystem.folder'); 93 | jimport('joomla.filesystem.file'); 94 | 95 | // Tell JFactory where to find the current application object 96 | JFactory::$application = $this; 97 | 98 | // Start a new session and tell JFactory where to find it if we're on Joomla 3 99 | if(version_compare(JVERSION, '3.0.0', '>=')) { 100 | JFactory::$session = $this->_startSession(); 101 | } 102 | 103 | // Load required languages 104 | $lang = JFactory::getLanguage(); 105 | $lang->load('lib_joomla', JPATH_ADMINISTRATOR, null, true); 106 | $lang->load('com_installer', JPATH_ADMINISTRATOR, null, true); 107 | } 108 | 109 | /** 110 | * Authenticates the Joomla user. 111 | * 112 | * This method will load the default user object and change its guest status to logged in. 113 | * It will then simply copy all the properties defined by key in the $credentials argument 114 | * onto this JUser object, allowing you to completely overwrite the user information. 115 | * 116 | * @param array $credentials Associative array containing user object properties. 117 | * 118 | * @return void 119 | */ 120 | public function authenticate($credentials) 121 | { 122 | $user = JFactory::getUser(); 123 | $user->guest = 0; 124 | 125 | foreach($credentials as $key => $value) { 126 | $user->$key = $value; 127 | } 128 | 129 | JFactory::getSession()->set('user', $user); 130 | } 131 | 132 | /** 133 | * Check if the Composer package located at the given path is installed or not. 134 | * 135 | * This method will look for the package manifest at the given 136 | * directory. It will extract the extension name from the manifest 137 | * and see if that element is installed in the database. 138 | * 139 | * @param string $installPath Path to Composer package 140 | * @return bool 141 | */ 142 | public function isInstalled($installPath) 143 | { 144 | $manifest = Util::getPackageManifest($installPath); 145 | 146 | if ($manifest === false) { 147 | return false; 148 | } 149 | 150 | $xml = simplexml_load_file($manifest); 151 | 152 | if($xml instanceof \SimpleXMLElement) 153 | { 154 | $type = (string) $xml->attributes()->type; 155 | $element = Util::getNameFromManifest($installPath); 156 | 157 | if (empty($element)) { 158 | return false; 159 | } 160 | 161 | $extension = $this->getExtension($element, $type); 162 | 163 | if (!is_object($extension)) { 164 | return false; 165 | } 166 | 167 | return isset($extension->id) && $extension->id > 0; 168 | } 169 | 170 | return false; 171 | } 172 | 173 | /** 174 | * Get the extension info from Joomla's #__extensions table 175 | * 176 | * @param string $element The name of the element 177 | * @param string $type The type of extension 178 | * @param string $group Only for plugins 179 | * 180 | * @return bool 181 | */ 182 | public function getExtension($element, $type = 'component', $group = null) 183 | { 184 | $db = JFactory::getDbo(); 185 | $sql = "SELECT `extension_id` AS `id`, `state` FROM `#__extensions`" 186 | ." WHERE `element` = ".$db->quote($element)." AND `type` = ".$db->quote($type); 187 | 188 | if ($type == 'plugin' && !empty($group)) { 189 | $sql .= ' AND `folder` =' . $db->quote($group); 190 | } 191 | 192 | $extension = $db->setQuery($sql)->loadObject(); 193 | 194 | if ($extension && $extension->state != -1); { 195 | return $extension; 196 | } 197 | 198 | return false; 199 | } 200 | 201 | /** 202 | * Installs an extension from the given path. 203 | * 204 | * @param string $path Path to the extracted installation package. 205 | * 206 | * @return bool 207 | */ 208 | public function install($path) 209 | { 210 | $installer = $this->getInstaller(); 211 | 212 | return $installer->install($path); 213 | } 214 | 215 | /** 216 | * Updates an existing extension from the given path. 217 | * 218 | * @param string $path Path to the extracted installation package. 219 | * 220 | * @return bool 221 | */ 222 | public function update($path) 223 | { 224 | $installer = $this->getInstaller(); 225 | 226 | return $installer->update($path); 227 | } 228 | 229 | /** 230 | * Uninstalls the given extension 231 | * 232 | * @param int $id ID of the extension row 233 | * @param string $type Type of extension (component, module, ..) 234 | * 235 | * @return bool 236 | */ 237 | public function uninstall($id, $type) 238 | { 239 | $installer = $this->getInstaller(); 240 | 241 | return $installer->uninstall($type, $id); 242 | } 243 | 244 | /** 245 | * Retrieves value from the Joomla configuration. 246 | * 247 | * @param string $varname Name of the configuration property 248 | * @param mixed $default Default value 249 | * 250 | * @return mixed 251 | */ 252 | public function getCfg($varname, $default = null) 253 | { 254 | return JFactory::getConfig()->get($varname, $default); 255 | } 256 | 257 | /** 258 | * Enqueue flash message. 259 | * 260 | * @param string $msg The message 261 | * @param string $type Type of message (can be message/notice/error) 262 | * 263 | * @return void 264 | */ 265 | public function enqueueMessage($msg, $type = 'message') 266 | { 267 | $this->_messageQueue[] = array('message' => $msg, 'type' => strtolower($type)); 268 | } 269 | 270 | /** 271 | * Return all currently enqueued flash messages. 272 | * 273 | * @return array 274 | */ 275 | public function getMessageQueue() 276 | { 277 | return $this->_messageQueue; 278 | } 279 | 280 | /** 281 | * Get the JInstaller object. 282 | * 283 | * @return JInstaller 284 | */ 285 | public function getInstaller() 286 | { 287 | // @TODO keep one instance available per install package 288 | // instead of instantiating a new object each time. 289 | // Re-using the same instance for multiple installations will fail. 290 | return new JInstaller(); 291 | } 292 | 293 | /** 294 | * Get the current template name. 295 | * Always return 'system' as template. 296 | * 297 | * @return string 298 | */ 299 | public function getTemplate() 300 | { 301 | return 'system'; 302 | } 303 | 304 | /** 305 | * Get the current application name. 306 | * Always returns 'cli'. 307 | * 308 | * @return string 309 | */ 310 | public function getName() 311 | { 312 | return 'cli'; 313 | } 314 | 315 | /** 316 | * Checks if interface is site or not. 317 | * 318 | * @return bool 319 | */ 320 | public function isSite() 321 | { 322 | return $this->isClient('site'); 323 | } 324 | 325 | /** 326 | * Checks if interface is admin or not. 327 | * 328 | * @return bool 329 | */ 330 | public function isAdmin() 331 | { 332 | return $this->isClient('administrator'); 333 | } 334 | 335 | /** 336 | * Check the client interface by name. 337 | * 338 | * @param string $identifier String identifier for the application interface 339 | * 340 | * @return boolean True if this application is of the given type client interface. 341 | * 342 | * @since 3.7.0 343 | */ 344 | public function isClient($identifier) 345 | { 346 | return $this->getName() === $identifier; 347 | } 348 | 349 | /** 350 | * Method to load a PHP configuration class file based on convention and return the instantiated data object. You 351 | * will extend this method in child classes to provide configuration data from whatever data source is relevant 352 | * for your specific application. 353 | * Additionally injects the root_user into the configuration. 354 | * 355 | * @param string $file The path and filename of the configuration file. If not provided, configuration.php 356 | * in JPATH_BASE will be used. 357 | * @param string $class The class name to instantiate. 358 | * 359 | * @return mixed Either an array or object to be loaded into the configuration object. 360 | * 361 | * @since 11.1 362 | */ 363 | protected function fetchConfigurationData($file = '', $class = 'JConfig') 364 | { 365 | $config = parent::fetchConfigurationData($file, $class); 366 | 367 | // Inject the root user configuration 368 | if(isset($this->_options['root_user'])) 369 | { 370 | $root_user = isset($this->_options['root_user']) ? $this->_options['root_user'] : 'root'; 371 | 372 | if (is_array($config)) { 373 | $config['root_user'] = $root_user; 374 | } 375 | elseif (is_object($config)) { 376 | $config->root_user = $root_user; 377 | } 378 | } 379 | 380 | return $config; 381 | } 382 | 383 | /** 384 | * Creates a new Joomla session. 385 | * 386 | * @return JSession 387 | */ 388 | protected function _startSession() 389 | { 390 | $name = md5($this->getCfg('secret') . get_class($this)); 391 | $lifetime = $this->getCfg('lifetime') * 60 ; 392 | $handler = $this->getCfg('session_handler', 'none'); 393 | 394 | $options = array( 395 | 'name' => $name, 396 | 'expire' => $lifetime 397 | ); 398 | 399 | $session = JSession::getInstance($handler, $options); 400 | $session->initialise($this->input, $this->dispatcher); 401 | 402 | if ($session->getState() == 'expired') { 403 | $session->restart(); 404 | } else { 405 | $session->start(); 406 | } 407 | 408 | return $session; 409 | } 410 | 411 | /** 412 | * Load an object or array into the application configuration object. 413 | * 414 | * @param mixed $data Either an array or object to be loaded into the configuration object. 415 | * 416 | * @return Application Instance of $this 417 | */ 418 | public function loadConfiguration($data) 419 | { 420 | parent::loadConfiguration($data); 421 | 422 | JFactory::$config = $this->config; 423 | 424 | return $this; 425 | } 426 | 427 | /** 428 | * Determine if we are using a secure (SSL) connection. 429 | * 430 | * This method is a stub; Joomla 3.2.x requires this method to be available in the application object. 431 | * 432 | * @return boolean false 433 | * @since 12.2 434 | */ 435 | public function isSSLConnection() 436 | { 437 | return false; 438 | } 439 | 440 | /** 441 | * Does nothing 442 | * 443 | * This method is a stub; Some extensions use JFactory::getApplication()->redirect() inside their installscripts (such as NoNumberInstallerHelper) 444 | */ 445 | public function redirect() 446 | { 447 | } 448 | 449 | /** 450 | * Flush the media version to refresh versionable assets 451 | * 452 | * @return void 453 | * 454 | * @since 3.2 455 | */ 456 | public function flushAssets() 457 | { 458 | $version = new JVersion(); 459 | $version->refreshMediaVersion(); 460 | } 461 | 462 | /** 463 | * Returns the application JRouter object. 464 | * 465 | * @param string $name The name of the application. 466 | * @param array $options An optional associative array of configuration settings. 467 | * 468 | * @return JRouter 469 | * 470 | * @since 3.2 471 | */ 472 | public static function getRouter($name = 'administrator', array $options = array()) 473 | { 474 | if (!isset($name)) 475 | { 476 | $app = JFactory::getApplication(); 477 | $name = $app->getName(); 478 | } 479 | 480 | try 481 | { 482 | $router = JRouter::getInstance($name, $options); 483 | } 484 | catch (Exception $e) 485 | { 486 | return null; 487 | } 488 | 489 | return $router; 490 | } 491 | 492 | /** 493 | * Enable logging to stdout of Joomla system messages. 494 | * 495 | * @param int $loglevel The log level 496 | * @return void 497 | */ 498 | protected function _setupLogging($loglevel) 499 | { 500 | // Backwards compatibility 501 | if (file_exists(JPATH_LIBRARIES . '/src/Log/Log.php')) { 502 | require_once JPATH_LIBRARIES . '/src/Log/Log.php'; 503 | } else { 504 | require_once JPATH_LIBRARIES . '/joomla/log/log.php'; 505 | } 506 | 507 | if ($loglevel == OutputInterface::VERBOSITY_NORMAL) { 508 | return; 509 | } 510 | 511 | switch ($loglevel) 512 | { 513 | case OutputInterface::VERBOSITY_DEBUG: 514 | $priority = JLog::ALL; 515 | break; 516 | case OutputInterface::VERBOSITY_VERY_VERBOSE: 517 | $priority = JLog::ALL & ~JLog::DEBUG; 518 | break; 519 | case OutputInterface::VERBOSITY_VERBOSE: 520 | $priority = JLog::ALL & ~JLog::DEBUG & ~JLog::INFO & ~JLog::NOTICE; 521 | break; 522 | } 523 | 524 | if ($this->_is_platform === true || version_compare(JVERSION, '3.0.0', '>=')) 525 | { 526 | $callback = function ($entry) { 527 | $priorities = array( 528 | JLog::EMERGENCY => 'EMERGENCY', 529 | JLog::ALERT => 'ALERT', 530 | JLog::CRITICAL => 'CRITICAL', 531 | JLog::ERROR => 'ERROR', 532 | JLog::WARNING => 'WARNING', 533 | JLog::NOTICE => 'NOTICE', 534 | JLog::INFO => 'INFO', 535 | JLog::DEBUG => 'DEBUG' 536 | ); 537 | 538 | $message = $priorities[$entry->priority] . ': ' . $entry->message . (empty($entry->category) ? '' : ' [' . $entry->category . ']') . "\n"; 539 | 540 | fwrite(STDERR, $message); 541 | }; 542 | 543 | $options = array('logger' => 'callback', 'callback' => $callback); 544 | } 545 | else 546 | { 547 | require_once dirname(__DIR__) . '/Joomla/Legacy/JLoggerStderr.php'; 548 | 549 | $options = array('logger' => 'stderr'); 550 | } 551 | 552 | 553 | JLog::addLogger($options, $priority); 554 | } 555 | 556 | public function __destruct() 557 | { 558 | // Clean-up to prevent PHP calling the session object's __destruct() method; 559 | // which will burp out Fatal Errors all over the place because the MySQLI connection 560 | // has already closed at that point. 561 | $session = \JFactory::$session; 562 | 563 | if(!is_null($session) && is_a($session, 'JSession')) { 564 | $session->close(); 565 | } 566 | } 567 | } 568 | 569 | /** 570 | * Workaround for Joomla 3.4+ 571 | * 572 | * Fix Fatal error: Call to undefined function Composer\Autoload\includeFile() in /libraries/ClassLoader.php on line 43 573 | * 574 | * Fix Fatal error: Cannot redeclare Composer\Autoload\includeFile() (previously declared in 575 | * phar:///usr/bin/composer/vendor/composer/ClassLoader.php:410) in /vendor/joomlatools/installer/src/Joomlatools/Composer/Application.php 576 | * on line 403 577 | */ 578 | namespace Composer\Autoload; 579 | 580 | if( !function_exists('Composer\Autoload\includeFile') ) 581 | { 582 | function includeFile($file) 583 | { 584 | include $file; 585 | } 586 | } 587 | -------------------------------------------------------------------------------- /src/Joomlatools/Joomla/Bootstrapper.php: -------------------------------------------------------------------------------- 1 | 7 | * @link http://github.com/joomlatools/joomlatools-composer for the canonical source repository 8 | */ 9 | 10 | namespace Joomlatools\Joomla; 11 | 12 | use Composer\IO\IOInterface; 13 | use Symfony\Component\Console\Output\OutputInterface; 14 | /** 15 | * Joomla bootstrapper class 16 | * 17 | * @author Steven Rombauts 18 | * @package Joomlatools\Joomla 19 | */ 20 | class Bootstrapper 21 | { 22 | /** @var Bootstrapper $__instance */ 23 | private static $__instance = null; 24 | 25 | /** @var IOInterface $_io */ 26 | protected $_io = null; 27 | /** @var Application $__application */ 28 | protected $_application; 29 | /** @var bool $_bootstrapped */ 30 | protected $_bootstrapped = false; 31 | 32 | protected $_verbosity = OutputInterface::VERBOSITY_NORMAL; 33 | protected $_credentials = array(); 34 | 35 | /** 36 | * Get instance of this class 37 | * 38 | * @return Bootstrapper $instance 39 | */ 40 | public static function getInstance() 41 | { 42 | if (!self::$__instance) { 43 | self::$__instance = new Bootstrapper(); 44 | } 45 | 46 | return self::$__instance; 47 | } 48 | 49 | public function setIO(IOInterface $io) 50 | { 51 | if ($this->_bootstrapped) 52 | { 53 | if ($this->_io->isVeryVerbose()) { 54 | $io->write('Application has already been bootstrapped. Can not set different IOInterface.', true); 55 | } 56 | 57 | return; 58 | } 59 | 60 | $this->_io = $io; 61 | 62 | if ($io->isDebug()) { 63 | $this->_verbosity = OutputInterface::VERBOSITY_DEBUG; 64 | } elseif ($io->isVeryVerbose()) { 65 | $this->_verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE; 66 | } elseif ($io->isVerbose()) { 67 | $this->_verbosity = OutputInterface::VERBOSITY_VERBOSE; 68 | } 69 | } 70 | 71 | public function setCredentials(array $credentials) 72 | { 73 | if (!($this->_io instanceof IOInterface)) { 74 | throw new \RuntimeException('Bootstrapper instance requires IOInterface instance. Please call setIO() first.'); 75 | } 76 | 77 | if ($this->_bootstrapped) 78 | { 79 | if ($this->_io->isVeryVerbose()) { 80 | $this->_io->write('Application has already been bootstrapped. Can not set new credentials.', true); 81 | } 82 | 83 | return; 84 | } 85 | 86 | $defaults = array( 87 | 'name' => 'root', 88 | 'username' => 'root', 89 | 'groups' => array(8), 90 | 'email' => 'root@localhost.home' 91 | ); 92 | 93 | $this->_credentials = array_merge($defaults, $credentials); 94 | } 95 | 96 | /** 97 | * Get the application instance. 98 | * If it 's not initialised yet, bootstrap the application. 99 | * 100 | * @return \Joomlatools\Joomla\Application/bool $application Application instance on success or false on failure 101 | * @throws Exception $exception 102 | */ 103 | public function getApplication() 104 | { 105 | if (!($this->_io instanceof IOInterface)) { 106 | throw new \RuntimeException('Bootstrapper instance requires IOInterface instance. Please call setIO() first.'); 107 | } 108 | 109 | if (!$this->_bootstrapped) { 110 | $this->_bootstrap(); 111 | } 112 | 113 | if (!($this->_application instanceof Application)) 114 | { 115 | $options = array( 116 | 'root_user' => $this->_credentials['username'], 117 | 'loglevel' => $this->_verbosity, 118 | 'platform' => Util::isJoomlatoolsPlatform() 119 | ); 120 | 121 | try 122 | { 123 | $this->_application = new Application($options); 124 | $this->_application->authenticate($this->_credentials); 125 | } 126 | catch (\Exception $ex) 127 | { 128 | $this->_io->write("Failed to initialize the Joomla application"); 129 | 130 | if ($this->_io->isVerbose()) { 131 | $this->_io->write($ex->getMessage()); 132 | } 133 | 134 | if ($this->_io->isDebug()) { 135 | throw $ex; 136 | } 137 | 138 | $this->_application = false; 139 | } 140 | } 141 | 142 | return $this->_application; 143 | } 144 | 145 | /** 146 | * Bootstraps the Joomla application 147 | * 148 | * @return void 149 | */ 150 | protected function _bootstrap() 151 | { 152 | if($this->_bootstrapped) { 153 | return; 154 | } 155 | 156 | $_SERVER['HTTP_HOST'] = 'localhost'; 157 | $_SERVER['HTTP_USER_AGENT'] = 'Composer'; 158 | 159 | define('DS', DIRECTORY_SEPARATOR); 160 | 161 | $base = realpath('.'); 162 | 163 | if (Util::isJoomlatoolsPlatform()) 164 | { 165 | define('JPATH_WEB' , $base.'/web'); 166 | define('JPATH_ROOT' , $base); 167 | define('JPATH_BASE' , JPATH_ROOT . '/app/administrator'); 168 | define('JPATH_CACHE' , JPATH_ROOT . '/cache/site'); 169 | define('JPATH_THEMES', __DIR__.'/templates'); 170 | 171 | // Joomlatools Platform <= v1.0.2 defined the _JEXEC constant 172 | // in the web/index.php and web/administrator/index.php files. 173 | // In later versions it was moved to app/defines.php. 174 | // If app/defines.php does not contain the define() call, set it manually. 175 | // Reading the JVersion file is impossible either as we would need to 176 | // define JPATH_PLATFORM twice (throwing more errors). 177 | $string = file_get_contents(JPATH_ROOT.'/app/defines.php'); 178 | if (strpos($string, "define('_JEXEC', 1)") === false) { 179 | define('_JEXEC', 1); 180 | } 181 | 182 | require_once JPATH_ROOT . '/app/defines.php'; 183 | require_once JPATH_ROOT . '/app/bootstrap.php'; 184 | 185 | require_once JPATH_LIBRARIES . '/import.php'; 186 | 187 | require_once JPATH_LIBRARIES . '/cms.php'; 188 | } 189 | else 190 | { 191 | define('_JEXEC', 1); 192 | define('JPATH_BASE', $base); 193 | 194 | require_once JPATH_BASE . '/includes/defines.php'; 195 | require_once JPATH_BASE . '/includes/framework.php'; 196 | 197 | require_once JPATH_LIBRARIES . '/cms.php'; 198 | 199 | stream_wrapper_restore('phar'); 200 | } 201 | 202 | $this->_bootstrapped = true; 203 | 204 | 205 | } 206 | } -------------------------------------------------------------------------------- /src/Joomlatools/Joomla/Legacy/JLoggerStderr.php: -------------------------------------------------------------------------------- 1 | 7 | * @link http://github.com/joomlatools/joomlatools-composer for the canonical source repository 8 | */ 9 | 10 | /** 11 | * STDERR Joomla Logger 12 | * 13 | * This class adds legacy support for Joomla 2.5 logging to STDERR. 14 | * 15 | * @author Steven Rombauts 16 | * @package Joomlatools\Composer 17 | */ 18 | class JLoggerStderr extends JLogger 19 | { 20 | protected $priorities = array( 21 | JLog::EMERGENCY => 'EMERGENCY', 22 | JLog::ALERT => 'ALERT', 23 | JLog::CRITICAL => 'CRITICAL', 24 | JLog::ERROR => 'ERROR', 25 | JLog::WARNING => 'WARNING', 26 | JLog::NOTICE => 'NOTICE', 27 | JLog::INFO => 'INFO', 28 | JLog::DEBUG => 'DEBUG' 29 | ); 30 | 31 | public function addEntry(JLogEntry $entry) 32 | { 33 | $message = $this->priorities[$entry->priority] . ': ' . $entry->message . (empty($entry->category) ? '' : ' [' . $entry->category . ']') . "\n"; 34 | 35 | fwrite(STDERR, $message); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Joomlatools/Joomla/Util.php: -------------------------------------------------------------------------------- 1 | 7 | * @link http://github.com/joomlatools/joomlatools-composer for the canonical source repository 8 | */ 9 | 10 | namespace Joomlatools\Joomla; 11 | 12 | /** 13 | * Joomla utility class 14 | * 15 | * @author Steven Rombauts 16 | * @package Joomlatools\Joomla 17 | */ 18 | class Util 19 | { 20 | private static $__manifests = array(); 21 | 22 | public static function getPlatformName() 23 | { 24 | return static::isJoomlatoolsPlatform() ? 'Joomlatools Platform' : 'Joomla'; 25 | } 26 | 27 | /** 28 | * Validate if the current working directory has a valid Joomla installation 29 | * 30 | * @return bool 31 | */ 32 | 33 | public static function isJoomla() 34 | { 35 | $directories = array('./libraries/cms', './libraries/joomla', './index.php', './administrator/index.php'); 36 | 37 | foreach ($directories as $directory) 38 | { 39 | $path = realpath($directory); 40 | 41 | if (!file_exists($path)) { 42 | return false; 43 | } 44 | } 45 | 46 | return true; 47 | } 48 | 49 | public static function isJoomla4() 50 | { 51 | $directories = array('./libraries/src', './libraries/vendor/joomla', './index.php', './administrator/index.php'); 52 | 53 | foreach ($directories as $directory) 54 | { 55 | $path = realpath($directory); 56 | 57 | if (!file_exists($path)) { 58 | return false; 59 | } 60 | } 61 | 62 | return true; 63 | } 64 | 65 | /** 66 | * Check if the working directory has Joomlatools Platform installed 67 | * 68 | * @return bool 69 | */ 70 | public static function isJoomlatoolsPlatform() 71 | { 72 | $manifest = realpath('./composer.json'); 73 | 74 | if (file_exists($manifest)) 75 | { 76 | $contents = file_get_contents($manifest); 77 | $package = json_decode($contents); 78 | 79 | if (isset($package->name) && in_array($package->name, array('joomlatools/platform', 'joomlatools/joomla-platform'))) { 80 | return true; 81 | } 82 | } 83 | 84 | return false; 85 | } 86 | 87 | public static function isReusableComponent(\Composer\Package\PackageInterface $package) 88 | { 89 | $extra = $package->getExtra(); 90 | 91 | return (is_array($extra) && isset($extra['joomlatools-component'])); 92 | } 93 | 94 | /** 95 | * Find the XML manifest of the installation package 96 | * 97 | * @param string $installPath Install path of package 98 | * 99 | * @return string Full path to manifest file 100 | */ 101 | public static function getPackageManifest($installPath) 102 | { 103 | if (!array_key_exists($installPath, self::$__manifests)) 104 | { 105 | self::$__manifests[$installPath] = false; 106 | 107 | $directories = new \RecursiveDirectoryIterator($installPath); 108 | $iterator = new \RecursiveIteratorIterator($directories); 109 | 110 | $iterator->setMaxDepth(1); 111 | 112 | $files = new \RegexIterator($iterator, '/.*\.xml$/', \RegexIterator::GET_MATCH); 113 | $manifests = array(); 114 | foreach($files as $file) { 115 | $manifests = array_unique(array_merge($manifests, $file)); 116 | } 117 | 118 | if (count($manifests)) 119 | { 120 | // Sort the results by number of subdirectories (root first, then subdirectories) 121 | usort($manifests, function ($a, $b) { 122 | $partsA = explode(DIRECTORY_SEPARATOR, $a); 123 | $partsB = explode(DIRECTORY_SEPARATOR, $b); 124 | 125 | return count($partsA) - count($partsB); 126 | }); 127 | 128 | foreach ($manifests as $manifest) 129 | { 130 | $xml = simplexml_load_file($manifest); 131 | 132 | if (!($xml instanceof \SimpleXMLElement)) { 133 | continue; 134 | } 135 | 136 | if ($xml->getName() == 'extension') { 137 | self::$__manifests[$installPath] = $manifest; 138 | } 139 | 140 | unset($xml); 141 | } 142 | } 143 | } 144 | 145 | return self::$__manifests[$installPath]; 146 | } 147 | 148 | /** 149 | * Set or overwrite the XML manifest path for the given install package. 150 | * 151 | * @param $package Install path of package 152 | * @param $filename Full path to XML manifest 153 | * 154 | * @return void 155 | */ 156 | public static function setPackageManifest($package, $filename) 157 | { 158 | self::$__manifests[$package] = $filename; 159 | } 160 | 161 | /** 162 | * Get the element name from the XML manifest 163 | * 164 | * @param string $manifest Path to the installation package 165 | * 166 | * @return string|bool Extension name or FALSE on failure 167 | */ 168 | public static function getNameFromManifest($installPath) 169 | { 170 | $manifest = self::getPackageManifest($installPath); 171 | 172 | if ($manifest === false) { 173 | return false; 174 | } 175 | 176 | $xml = simplexml_load_file($manifest); 177 | 178 | if (!($xml instanceof \SimpleXMLElement)) { 179 | return false; 180 | } 181 | 182 | $element = false; 183 | $type = (string) $xml->attributes()->type; 184 | 185 | switch($type) 186 | { 187 | case 'component': 188 | $name = strtolower((string) $xml->name); 189 | $element = preg_replace('/[^A-Z0-9_\.-]/i', '', $name); 190 | 191 | if (substr($element, 0, 4) != 'com_') { 192 | $element = 'com_'.$element; 193 | } 194 | break; 195 | case 'module': 196 | case 'plugin': 197 | if(count($xml->files->children())) 198 | { 199 | foreach($xml->files->children() as $file) 200 | { 201 | if ((string) $file->attributes()->$type) 202 | { 203 | $element = (string) $file->attributes()->$type; 204 | break; 205 | } 206 | } 207 | } 208 | break; 209 | case 'file': 210 | case 'library': 211 | $filename = basename($manifest); 212 | $element = substr($filename, 0, -strlen('.xml')); 213 | break; 214 | case 'package': 215 | $element = preg_replace('/[^A-Z0-9_\.-]/i', '', $xml->packagename); 216 | 217 | if (substr($element, 0, 4) != 'pkg_') { 218 | $element = 'pkg_'.$element; 219 | } 220 | break; 221 | case 'language': 222 | $element = (string) $xml->tag; 223 | break; 224 | case 'template': 225 | $name = preg_replace('/[^A-Z0-9_ \.-]/i', '', $xml->name); 226 | $element = strtolower(str_replace(' ', '_', $name)); 227 | break; 228 | default: 229 | break; 230 | } 231 | 232 | return $element; 233 | } 234 | } 235 | --------------------------------------------------------------------------------