I am creating search application using elasticsearch. I want to make indexing with zero downtime. I found one solution using aliases with client library in php. But I don't know how to implement it using client library in php.
In order to add an alias to an existing index, you need to call the updateAliases method:
$params['body'] = array(
'actions' => array(
array(
'add' => array(
'index' => 'your_index',
'alias' => 'your_alias'
)
)
)
);
$client->indices()->updateAliases($params);
If you are looking for a more complete solution, have a look at http://elasticorn.net - you can configure your index via yaml and it automatically creates them with aliases and the possibility to remap / reconfigure indices on the fly.
Related
I was going through Form Creation in ZF2 and I read the following statement.
"
You can create the entire form, and input filter, using the Factory. This is particularly nice if you want to store your forms as pure configuration; you can simply pass the configuration to the factory and be done."
Can anybody tell in detail what does PURE CONFIGURATION mean?
It means that you're able to store your forms within any config file, e.g. module.config.php and then pass this configuration key into the form factory. This is similar what has been done in ZF1 often times, too.
This whole process is done through the Zend\Form\Factory and if you check out the source code you'll see that you could pass it the following array to create a Form
$someConfig = array(
'form-key-name' => array(
'fieldsets' => array(
'fieldset_1' => array(
'elements' => array(
'elem_x' => array(/** Single Form-Element Array*/)
),
'fieldsets' => array(
'fs_y' => array(/** More Sub-Fieldset Array*/)
),
)
)
)
);
Note that this example is quite incomplete (missing name => foo), hydrator configuration, inputFilter configuration, etc... but as it is this should give you a idea of what's meant by that statement.
Using the above-mentioned configuration then you can pass it to the factory
$factory = new \Zend\Form\Factory();
$form = $factory->createForm($someConfig['form-key-name']);
For a Web-Application with many Database related events I want to build a Changelog. That should log what users have done, so its a Userlog too.
The App is huge, has a complex role based user access system and there will be hundreds of different events (changes) that may occur.
This all should be Database-Driven, in PHP and needs at least a View to search the Logs.
But in short, I have totally no idea how to design that all and need some tips or inspirations, maybe what others have done.
I've done this in the past and found basically 2 approaches: Model-based and Controller-based.
Model-based within the model itself override the save and update methods (assuming an ActiveRecord pattern) to create a new entry in the ChangeLog table.
Controller-based add the ChangeLog record creation logic to each controller that you want to track.
I prefer the Controller-based approach since you have more control over what's going on and when. Also, you have full access to the user session so it's easier to add tracking for auditing purposes.
Have solved that much more easy as it appears with my first thoughts.
This should do it most times without a comment:
protected function log($comment = ''){
$user = $this->user();
ORM::factory('Changelog')->vaules(array(
'user_id' => $user->pk(),
'section_id' => $user->section->pk(),
'username' => $user->username.'#'.$user->section->name,
'time' => time(),
'uri' => $this->uri($this->request->param(), $this->request->query()),
'controller' => $this->request->controller(),
'action' => $this->request->action(),
'post' => serialize($this->request->post()),
'comment' => $comment,
))->save();
}
A simple $this->log() and all is done.
Result: http://charterix.sourceforge.net/log.jpg
i'm searching for a solution to solve the following problem in zf2:
i have a list of destinations, and i want a search-formular on my page with auto-completion.
also the list is used to translate parts of my web-page, so i will use zend_translate to do this.
it it possible to "reverse-search" the list of translations with zend_translate?
Example:
$translate->getKeysByExpression('*ger*');
result:
array (
array ( 'key' => '__germany__', 'name' => 'germany'),
array ( 'key' => '__trn_landwithger__', 'name' => 'landwithger'
)
it is not the biggest problem if i have to load the complete list of translations, it is not that much.
or is it better to use mongodb as backend for zend_translate, and use direct queries to find the completion-candidates?
I just read the Rob Allen's akrabat ZF2 tutorial (http://akrabat.com/wp-content/uploads/Getting-Started-with-Zend-Framework-2.pdf) on how to inject dependencies into your stuff like, injecting in your table adapter into your table classes.
This seems to be how I'm supposed to do it:
array(
'Application\Model\DbTable\UserTable',
) => array(
'parameters' => array(
'config' => 'Zend\Db\Adapter\PdoMysql',
)
),
array(
'Application\Model\DbTable\UserProfileTable',
) => array(
'parameters' => array(
'config' => 'Zend\Db\Adapter\PdoMysql',
)
),
Ok that's pretty cool but I've got around 84 tables so am I going to have to add each of these and say that I want PdoMySQL injecting into them all. Is there any proper way to do this such as specifying my entire DbTable folder? Not even this works:
array(
'Application\Model\DbTable\UserTable',
'Application\Model\DbTable\UserProfileTable'
) => array(
'parameters' => array(
'config' => 'Zend\Db\Adapter\PdoMysql',
)
),
Anyone else doing this and found a better solution?
Thanks, Dom
Your question is a good one, and I agree, this a scenario where dependency injection does NOT make sense. I haven't browsed the ZF2 API yet, did they completely abandon the ability to bind adapter at the connection level, rather than the table level?
In my database class I use a yaml file to store connection settings; username, password, adapter, etc. I did it in a format which can be passed straight to Zend_Config, which can then be passed to the Zend_Db class.
// Entry in connection.yml
database:
adapter: Pdo_Mysql
params:
host: myhost
dbname: mydatabase
username: myusername
password: mypassword
// Parse yaml file to get above snippet in an array ($dbConnectionparams)
$config = new Zend_Config($dbConnectionParams);
$dbo = Zend_Db::factory($config->database);
Now, If I ever need to change the adapter for a database connection I only need to change it in one location, the connection.yml file.
Also, I believe you can store this type of connection data in various other formats (xml, etc).
You should implement Zend\Db\Adapter\AdapterAwareInterface in your model classes and request them via service manager in your controllers. Take a look at my blog post for more details: http://cmyker.blogspot.com/2012/11/zend-framework-2-model-database-adapter.html
99% of what REST API's do is serve as a controlled interface between client and DB, and yet I can't for the life of me find any libraries that do just that.
All libraries focus on providing a REST interface to the developer, who then sets up the communication with the database. It seems like a no-brainer to me to create a library that already interfaces with the database, and all the developer needs to do is define some ACL rules and plug in some logic here or there.
So, before I continue and put my thoughts into actions by actually creating this sort of library, may I just ask anyone with knowledge on the subject; has anyone implemented anything like this yet? Will I be re-inventing the wheel?
I'm talking strictly about a PHP based solutions by the way, I have nothing against other languages, PHP is simply my cup of tea. But for that matter, I haven't found any implementations in other languages either.
And in case my explanation doesn't make it very clear, this is essentially what I'd want:
<?php
class post_controller extends controller {
protected static $config = array(
'select' => true,
'insert' => true,
'update' => true,
'delete' => false,
'fields' => array(
'id' => array(
'select' => true,
'update' => false
),
'name' => array(
'select' => true,
'update' => true
),
'content' => array(
'select' => true,
'update' => true
)
)
);
/**
* GET, POST, DELETE are implemented already by the parent controller
* Just overriding PUT to modify the content entry
*/
function put($data) {
$data->content = htmlentities($data);
return parent::put($data);
}
}
?>
Thanks in advance for anyone giving their input and apologies if this is not a proper Stackoverflow question.
Edit:
To clarify, this type of service would be for specific use-cases, I don't imagine it to be a type of thing that anyone can use for any type of web service.
I have built a similar system for SOAP and must say it's very easy to do so. I haven't seen any prebuilt libraries that would help you do it (and I doubt they exist - see next paragraph), but it shouldn't take you more than a few hours to build your own solution (a day max - with testing and documentation writing included).
It is however a whole another question if you really want to do that. REST can be (mis)used for this purpose, but it is meant for manipulating resources. Records in a database only rarely have a one-to-one mapping with resources. If they do in your case (as they did in mine) then feel free to do it, otherwise it would be nicer to provide a proper REST API. Why expose your internal DB structure to the world? YMMV, of course.