How to extend page indexing configuration of Solr TYPO3 extension? - solr

I have a working TYPO3-Solr setup (TYPO3 v9, Solr v9.1). Now I want the indexer to index the media field of the pages to get a nice preview image for the page:
plugin.tx_solr.index.queue.pages.fields {
(...)
image_stringS = FILES
image_stringS {
references {
table = pages
uid.data = page:uid
fieldName = media
}
maxItems = 1
renderObj = IMG_RESOURCE
renderObj.file.import.data = file:current:uid
}
}
But this doesn't have the effect I desire: the image_stringS field doesn't show up. For the news extension this code works (adapted to the fields of the news extension).
Any suggestions welcome, thanks.

Related

Map all existing aws security groups in terraform

I would like to source existing aws security group information allowing for them to be referenced by name rather than id.
I can reference a single existing instance using:
data "aws_security_groups" "single" {
filter {
name = "group-name"
values = ["Foo-all"]
}
}
output "singlename" {
value = "${data.aws_security_groups.single.ids[0]}"
}
This isn't ideal, as I would need to enter all the security group ids as their own block.
I can get all of the attributes for all of the security groups printed using:
data "aws_security_groups" "sgroups" {
filter {
name = "vpc-id"
values = ["${data.aws_vpc.vpc.id}"]
}
}
data "aws_security_group" "instances" {
count = length(data.aws_security_groups.sgroups.ids)
id = data.aws_security_groups.test.ids[count.index]
}
output "groupinfo" {
value = "${data.aws_security_group.instances}"
}
This isn't useful, to me, as I want a Name = id mapping.
What I'm hoping to do is define all of the existing security groups as a map so I could do something like the following:
resource "aws_instance" "fooTest" {
ami = "${var.ami}"
instance_type = "t2.nano"
subnet_id = "${var.subnets["Foo-net"]}"
key_name = "Fookey"
vpc_security_group_ids = [
"${var.existingsgs["Foo-all"]}",
]
}
Can this be done? Or is there a better way of achieving name based security group references?
I dont think you can output a map, you should be able to output a list of sec group id's using a data source like you've done with your example code. Take that a step further by filtering the data source to grab resources that are tagged with specific labels. Then just reference the data resource inside your aws_instance resource block.
Example by request:
To read existing vpc and security groups use a data source. Select the desired target by filtering on specific tags that are applied to the vpc and security groups.
data "aws_vpc" "my_vpc" {
tags = {
Project = "my_vpc"
Environment = "qa"
}
}
data "aws_security_group" "my_sg" {
vpc_id = "${data.aws_vpc.my_vpc.id}"
tags = {
Name = "my_sg"
Environment = "qa"
}
}
When you create your resource you can reference the data sources you have grabbed. Remember data sources are read first to make them available to use when creating additional resources.
resource "aws_instance" "fooTest" {
ami = "${var.ami}"
instance_type = "t2.nano"
subnet_id = "${var.subnets["Foo-net"]}"
key_name = "Fookey"
vpc_security_group_ids = ["${data.aws_security_group.my_sg.ids}"]
}
You can also do the same thing with subnets, nearly anything that exists in AWS can be read into a data source block for referencing when creating additional resources.
https://www.terraform.io/docs/configuration/data-sources.html

Taggit gets wrong tags

I have a Work model with Category Foreign Key. I am doing -->
drawingTags = Tag.objects.filter(Q(work__category__slug_en = 'drawing') |
Q(work__category__slug_en = 'illustration') |
Q(work__category__slug_en = 'sketch') |
Q(work__category__slug_en = 'storyboard'))
I get also the tags that do not belong to drawings ? Am i doing smt wrong ?
-- EDIT --
I did a little test. I have two applications named blog and web.
In blog i have 'entry' model and in web i have 'work' model. Both of those models have TaggableManager fields named tags...
When i want to take the tags of works categorized under drawing and do -->
drawingTags = Tag.objects.filter( work__in = drawings ).distinct()
If there is a drawing with id 1 and if entry model has an entry with id 1. Than i get both item's tags. I think there is a problem here but i do not know how to solve the puzzle?
Solution :
from django.contrib.contenttypes.models import ContentType
contentType = ContentType.objects.get_for_model(Work)
drawingTags =Tag.objects.filter(taggit_taggeditem_items__content_type=contentType,
work__in = drawings ).distinct()

Modifying Value in PHP/MySQL Database Query

I know the solution to this question is super simple, but I'm missing something.
I have a database filled with people's names. Most will be displayed # URL's like this:
MySite/People/Abraham_Lincoln
However, people who are only important in Washington State will be displayed # URL's like this:
MySite/People/Washington/Gary_Locke
Abraham Lincoln is simple because the value in the database table, field URL (Abraham_Lincoln), matches the URL (Abraham_Lincoln). However, the database value Gary_Locke does NOT match the URL Washington/Gary_Locke.
So I'm trying to modify my query so that if a person is associated with Washington (WHERE Site = 'WA'), the webpage URL ($MyURL) won't equal the database table field URL but Washington/ + URL.
But how do I append 'Washington/' and URL? The following query returns 0 results when I test it in SQL, and it doesn't work at all in my PHP page.
$result = mysql_result(mysql_query("SELECT COUNT(URL)
FROM people
WHERE URL = '$MyURL' AND Site = 'PX'
OR '$MyURL' = 'Washington/'URL AND Site = 'WA'"),0);
So, again, if I'm focusing on Gary Locke (Gary_Locke in field URL), then I want to be able to display information about him at MySite/People/Washington/Gary_Locke, NOT MySite/People/Gary_Locke.
Can anyone tell me what I'm doing wrong? Thanks.
Concat will join the Washington to URL see below
$result = mysql_result(mysql_query("SELECT COUNT(URL)
FROM people
WHERE URL = '$MyURL' AND Site = 'PX'
OR '$MyURL' = CONCAT('Washington/', URL) AND Site = 'WA'"),0);
Can I also suggest doing it this way, so that if you have an sql error, it will display the error, so you can tell what is wrong
$res = mysql_query("SELECT COUNT(URL)
FROM people
WHERE URL = '$MyURL' AND Site = 'PX'
OR '$MyURL' = CONCAT('Washington/', URL) AND Site = 'WA'");
if (!$res) {
die('Invalid query: ' . mysql_error());
}
$result = mysql_result($res, 0);
I also hope you are escaping your parameters, this will do the trick. (search for sql injection if you are not sure why that is a good idea)
$MyURL = mysql_real_escape_string($MyURL);
And finally, the mysql_ set of functions will be removed from the latest version of php very soon. You should look at mysqli or pdo if this is a long term project.

Ideas on how to implement CMS for language specific page

I'm building a web shop and I'm implementing language selection as well as a CMS. I also have to provide an administrator of the site with the means to be able to edit a page through the CMS.
Therein doesn't lay the problem.
The problem is how I should build up my tables for these pages. I've made my database design but didn't think the web pages part through.
I already have the following table structure for the info that is equal throughout all languages for a page (called Webpages) and for language or culture specific info (called Webpages_local).
Which attributes could I add or remove so that I can easily and dynamically perform the CRUD actions?
I'm using MVC4 with razor syntax with the following url structure:
url: "{language}/{controller}/{action}/{id}"
My main concern is now that I'm not sure on how to show the language specific content of a page when a visitor presses, for example, the link to the About page.
Maybe use the controller part of the url and save it as a key in my Webpages table and filter on that as well as the selected language?
So when a visitor goes to http://example.com/nl/About, I in my AboutController I retrieve "nl" and "about", of course filter them first and then with a query to the database select the correct nl content?
How should I go about this technically?
I would use OnActionExecuting to handle the retrieve lang process, something like:
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
#region set Language
var lang = string.Empty;
if (filterContext.RouteData.Values["lang"] != null && !string.IsNullOrWhiteSpace(filterContext.RouteData.Values["lang"].ToString()))
{
// set the culture from the route data (url {lang})
lang = filterContext.RouteData.Values["lang"].ToString();
switch (lang)
{
case "es":
break;
case "en":
break;
default:
lang = "es";//default language
filterContext.RouteData.Values["lang"] = lang;
filterContext.HttpContext.Response.Redirect("/");
break;
}
}
else
{
//set default language
lang = "es";
filterContext.RouteData.Values["lang"] = lang;
}
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(lang);
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
#endregion
base.OnActionExecuting(filterContext);
}
Then anywhere in your code you just read the Thread.CurrentThread.CurrentCulture (this will be your global lang indicator) to show the correct language.
UPDATE - know I understand your point =)
If the pages will be dynamically created then you wont have an ActionResult per page, you need just one ActionResult like:
public ActionResult ShowPage(int id,string slug)
{
//Use the slug to check for url attacks and ensure 301 redirections to the correct url
var page = db.Webpages_local.First(p=> p.id == id
&& p.culture.name == Thread.CurrentThread.CurrentCulture);
return View(page);
}
For SEO reasons i would suggest you define a route like:
routes.MapRoute(
name: "LocalizedPages",
url: "{lang}/p/{slug}/{id}",
defaults: new { controller = "Page", action = "Show", id = UrlParameter.Optional },
constraints: new { lang = #"(es|en|fr|nl)" }
);
That give you urls like:
/nl/p/about/1 //the p is just an identifier for 'page', to differentiate this routes from others
I would add a column called language or similar to your table instead of having multiple tables.
Then your controller can fetch the right page after finding the requested language key in your menu table and then it can read the content in your webpages table.

How can i set the Object Path in typo3 from db

I'm trying to find a way in typoScript to render a view, from its name that comes from the db...
Currently, I now do it in the Object path option in typo3 control Panel... I wonder if I can get this data from the db
Any Ideas?
For the first part, getting any value from the db and render it, try this:
lib.customValue = CONTENT
lib.customValue {
table = tx_any_table
select {
pidInList = 999
where = some_field = 999
max = 1
}
renderObj >
renderObj = COA_INT
renderObj {
10 = TEXT
10.field = any_field
}
}
But I assume that the string you now have represents a (part of a) typoscript object, and you need the value of this object to be rendered? Hope I (or someone else) can add some more info for that soon.
I finally find a typo3 extension
TypoScript code (typoscript_code) that allow me to render a t3 from the database.

Resources