pleini Posted November 27, 2014 Posted November 27, 2014 Hi there, I have 4 systems: system1: an independent processwire installation 2.5.3 with own database system2: an independent processwire installation 2.5.3 with own database system3: an independent processwire installation 2.5.3 with own database cronjobsystem: In a cronjob I want to access the processwire database from the systems with the easy Processwire API access On the cronjobsystem:Downloaded processwire, but I just want this system to use the easy API and to change the database dynamically to system 1-3.On the server there is just index.php the wire folder. Is this possible: $config = new Config(); $config->dbHost = IP_SYSTEM1 $config->dbName = DBNAME_SYSTEM1 $config->dbPass = DBPASS_SYSTEM1 $config->dbPort = 3306; include("index.php"); $pages_system1 = wire()->find("template=article"); var_dump($pages_system1); Questions:- Is this possible or what is the best way to achieve using the easy API access while the database comes from another system?- How can I initiate the class autoloader on the cronjobsystem? Thank you,Chris
Nico Knoll Posted November 28, 2014 Posted November 28, 2014 So you have one database for three PW installations? I think that wouldn't work because of the different asset folder contents. But I guess you should use something like this module, which enables you kind of external access to the api: http://modules.processwire.com/modules/service-pages/
pleini Posted November 28, 2014 Author Posted November 28, 2014 Hi Nico, thank you for your reply. It's three PW installations with three own databases. I don't want to access the asset folder, I just want to change some data inside the database with the ease of PW (e.g. page titles, some fields, ...) No file up or downloads. The module you suggested is the right direction! But it doesn't look like I can change data with it as well!?
Nico Knoll Posted November 28, 2014 Posted November 28, 2014 It's really easy actually. Just do the following for every installation (of course you have to secure it a lot more): 1. Create a new template called "api" 2. create a new page called "api" using that template -> Now you can open http://yoursite.com/api/ In the template file api.php you can for example process post or get parameters. Example: http://yoursite.com/api/?action=addPage And in your template file you have: if($_GET['action'] == "addPage") { // create page via api } And so on.
pleini Posted November 28, 2014 Author Posted November 28, 2014 I thought about a solution like this as well but I want to avoid writing API Endpoints. Just want the full control of the system and change data on other systems without adding new code.
Nico Knoll Posted November 28, 2014 Posted November 28, 2014 I guess that's not possible because of security.
pwFoo Posted November 29, 2014 Posted November 29, 2014 It's really easy actually. Just do the following for every installation (of course you have to secure it a lot more): 1. Create a new template called "api" 2. create a new page called "api" using that template -> Now you can open http://yoursite.com/api/ In the template file api.php you can for example process post or get parameters. Example: http://yoursite.com/api/?action=addPage And in your template file you have: if($_GET['action'] == "addPage") { // create page via api } And so on. I would do it like Nico wrote above... Requests should restricted to source ip address for security reasons. You have to write some code. Also your way won't work without custom code. So write a simple API and send needed params via GET sounds good.
Pete Posted November 30, 2014 Posted November 30, 2014 This might help, but does come with some restrictions: http://modules.processwire.com/modules/service-pages/
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now