fuseki 2.0.0 update seems not working - insert-update

i'm trying to update fuseki using this update request which is sent to http://localhost:3030/test/update :
DELETE { <http://example.org/resource/user38702668> <http://example.org/follower> ?a } INSERT{<http://example.org/resource/user38702668> <http://example.org/follower> <http://localhost/1212>} where{<http://example.org/resource/user38702668> <http://example.org/follower> ?a}
the fuseki webinterface returns
<html>
<head>
</head>
<body>
<h1>Success</h1>
<p>
Update succeeded
</p>
</body>
</html>
but when i query http://localhost:3030/test/update, i still have the original triple (i.e., not the updated one with value http://localhost:3030/test/update ) in fuseki. any thought?
Thanks

This is a late answer, but I had the same exact issue.
The problem is that Fuseki is quite sensitive towards the graphs. It needs to know which graph you want to remove your triples from, or it will look only in the default graph. So the response that it gives you (200, OK) is actually right because it couldn't find the triples to remove them and as such it worked! So if you change your query to something like:
with <graph_URL_here>
DELETE
{
<http://example.org/resource/user38702668> <http://example.org/follower> ?a
}
INSERT
{
<http://example.org/resource/user38702668> <http://example.org/follower> <http://localhost/1212>
}
where{
<http://example.org/resource/user38702668> <http://example.org/follower> ?a
}

Related

Laravel Livewire: All Methods are executed twice

I have a super weird issue in my project, and I'm trying to isolate the issue since 2 days and I can't find out why it happens and more important how to prevent it.
All methods in Livewire components are executed twice. Looks like they are executed almost at the same time
It seems like livewire is running twice in the backend. In most cases I don't even realize that the methods are executed twice. I can do even easy onclick counters that work as expected,but if I save a new instance of a model, I get 2 new identical models (apart from ID) and if I send out emails the email is sent out twice.
Here is what I tried and checked:
click event sends only one request to the server.
building click counters (public property on Component) into the method that's called -> it counts up once
it seems that the method is running twice at the same time with the same values.
I reinstalled Livewire and updated to latest Version 2.10 -> no difference
stripping back everything to a minimum with nothing in the view but the essentials -> same result
<html>
<head>
#livewireStyles
</head>
<body>
<livewire:test.simple-class />
#livewireScripts
</body>
</html>
My component
class SimpleClass extends Component
{
public $counter = 0;
public function render()
{
return view('livewire.test.simple-class');
}
public function clickMe()
{
$this->counter ++;
$admin = Auth::user();
$admin->notify(new SimpleNotification($admin, "Clicking in simple test field"));
}
}
The view of the component
<div>
<div>
<button class="btn btn-primary" wire:click='clickMe'>
Click me
</button>
</div>
{{$counter}}
</div>
The issue is not local, as I have exactly the same behavior on the production server.
On a fresh Laravel installation on the same local server the same Scenario works great -> One click count + 1 email
I also deleted the vendors folder and run composer install -> no difference
Please help!
I finally fixed it, by following the request the click event sends to the server. It's quite an old project and it has been updated many times and it appears I had an "error" in one of the middlewares: VerifyCsrfToken
After changing the lines, which I don't even remember why we've put it in there, the Livewire methods where executed only once.
Old:
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #return mixed
*/
public function handle($request, Closure $next)
{
parent::handle($request, $next);
unset($request['_token']);
return $next($request);
}
New:
public function handle($request, Closure $next)
{
unset($request['_token']);
return parent::handle($request, $next);
}

$te method doesn't find existing key if it contains spaces

I have already made a [issue][1] on the official vue-i18n page, but solving this issue would really help me out thats why I'm asking here too.
I'm using the translation key directly as the english translation so some translation keys look like this 'Next':'Weiter' and others contain spaces or even full sentences: 'This text is translated.':'Dieser Text ist übersetzt.'.
So to prevent a million warnings about the missing english translations I want to check for the key first(this.$te('key')) but this doesn't seem to work when the key contains spaces. It returns false even if the translation key is there and the translation is working.
Does someone know a solution to this or do I have to wait until someone addresses my issue on the github page/fixes it on the package itself?
Edit: The problem is fixed in the latest version of vue-i18n. My other problem still stands though. The missing handler option doesn't prevent the warning being thrown, so this doesn't work either.
I solved it by adding my own translation method on the vue instance:
Vue.prototype.$trans = function (key) {
return i18n.te(key) ? i18n.t(key) : key;
}
This way it only translates the key if it actually exists, but still will get complicated if I want to use pluralization etc. so its not a long term solution.
[1]: https://github.com/kazupon/vue-i18n/issues/1309
The problem you are describing indeed exists in a version 7.3.2 but that version is almost 4 years old and current version 8.24.5 works as expected - see example below
Also it seems to me that better way to avoid unneeded error messages would be to supply custom missing handler
var messages = {
en: {},
de: {
'Test translation': 'Test Übersetzung'
}
}
Vue.use(VueI18n)
var i18n = new VueI18n({
locale: 'de',
messages: messages
})
new Vue({
i18n: i18n
}).$mount('#app')
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.js"></script>
<script src="https://unpkg.com/vue-i18n#8"></script>
<!-- <script src="https://unpkg.com/vue-i18n#7.3.2/dist/vue-i18n.js"></script> -->
<div id="app">
<p>de (implicit): {{ $te("Test translation") }}</p>
<p>de: {{ $te("Test translation", 'de') }}</p>
<p>en: {{ $te("Test translation", 'en') }}</p>
</div>

Running a forEach loop in Mongoose, in reverse

I'm currently trying to make a faux blog style page. All the relevant information is in MongoDB and I'm extracting it using a forEach loop.
`<% blogs.forEach(function(blog){ %>
<img src="<%= blog.image %>" >
<%=blog.title%>
<span><%= blog.created.toDateString() %></span>
<p><%- blog.body.substring(0, 100) %>...</p>
<% }) %>`
The database contains these objects when you create/edit a post. When you run a forEach it will start at the beginning of the database and then work forwards. I'm trying to figure out how to make it go in reverse as a typical blog site will push older posts down the page when new content is posted (as of now it's displaying the first post first, second one second, etc.)
I thought about creating a for loop and constraining the length of it by using the .count() mongoose command but I can't seem to figure out how I can relate it the various objects in the database. Basically I'm trying to convert this forEach to use a variable (like [i]).
Use the Mongoose . It is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose makes it very easy to work with MongoDB. You can try these (some of these may not work properly) , hopefully it will help you.
model_name.find({}).sort('-date').exec(function(err, docs) { ... });
model_name.find({}).sort({date: -1}).exec(function(err, docs) { ... });
model_name.find({}).sort({date: 'desc'}).exec(function(err, docs) { ... });
model_name.find({}).sort({date: 'descending'}).exec(function(err, docs) { ... });
model_name.find({}).sort([['date', -1]]).exec(function(err, docs) { ... });
model_name.find({}, null, {sort: '-date'}, function(err, docs) { ... });
model_name.find({}, null, {sort: {date: -1}}, function(err, docs) { ... });

Laravel Queries / Controller Edits

So I am pretty new to Laravel, and I have spent the whole day fishing through various documentations but I am stuck on the way queries work within the actual application. Right now, I am trying to get some data in my database to display, and I looked at the query builder so that's where I am right now. I am also using a CRUD based admin panel for entry in the database. And since it is CRUD based, it has created the model and the controller already, so I am wondering if I need to edit any of those files to get this to work. Here is what the public function index() has right now (Using Laraadmin):
$module = Module::get('Events');
if(Module::hasAccess($module->id)) {
return View('la.events.index', [
'show_actions' => $this->show_action,
'listing_cols' => $this->listing_cols,
'module' => $module
]);
} else {
return redirect(config('laraadmin.adminRoute')."/");
}`
Obviously, I am trying to display some data from this Events table into my blade view. From what I was reading, I understood (or I thought) that it would be something similar to this:
foreach ($module as $module) {
echo $module->id;
}
But, I keep getting an error that whatever variable I pass in the loop is undefined, although I thought it was in the controller. Right now my model is just returning the view as well. Any help with this is greatly appreciated, or even just an explanation of the relationships with queries in Laravel. Thanks!
A few things to check when this happens:
Change module to a known array. This tests if your data array is set up correctly:
'module' => [ '1', '2', '3' ], // previously $module
Within the blade, now write a simple loop, such as:
#foreach ($module as $m)
{{ $m }}
#endforeach
If this version does work, then you know you have something up with your $module variable.
If the above still doesn't work, try to simplify your view request (temporarily):
view('foo', ['a' => 555]);
Then in foo.blade.php, simply have:
hello {{ a }}
EDIT
If all this seems to be correct, then the data being fetched is probably wrong (so its not a view issue). Try $module = Module::all();
It seems like you are returning a view that doesn't exist. If what you have now was correct, it would be looking for resources/views/la/events/index.blade.php Try replacing that return view line with this:
return view('events', [ ... rest of your variables ]);
And just a side note, on your foreach statement, it's probably best to use two separate variable names... so something like:
foreach ($module as $element) { ...

Safari Extension Questions

I'm in the process of building my first Safari extension--a very simple one--but I've run into a couple of problems. The extension boils down to a single, injected script that attempts to bypass the native feed handler and redirect to an http:// URI. My issues so far are twofold:
The "whitelist" isn't working the way I'd expect. Since all feeds are shown under the "feed://" protocol, I've tried to capture that in the whitelist as "feed://*/*" (with nothing in the blacklist), but I end up in a request loop that I can't understand. If I set blacklist values of "http://*/*" and "https://*/*", everything works as expected.
I can't figure out how to access my settings from my injected script. The script creates a beforeload event handler, but can't access my settings using the safari.extension.settings path indicated in the documentation.
I haven't found anything in Apple's documentation to indicate that settings shouldn't be available from my script. Since extensions are such a new feature, even Google returns limited relevant results and most of those are from the official documentation.
What am I missing?
UPDATE
So I'm hoping that the documentation is incomplete because it's borderline abysmal, but I've learned a bit about settings. It turns out that, from injection scripts, the SafariExtensionSettings object isn't available. Injection scripts only have access to the SafariContentExtension object (which isn't useful at all), but it's aliased in exactly the same manner (safari.extension.settings)--bad idea, IMO. As stated in the injection script documentation:
Important: When you use safari.extension from within an injected script, you are not addressing the SafariExtension class. You are addressing the SafariContentExtension class.
You have to use the messaging system to talk to a global HTML file which has access to the settings. It's kind of loopy, but I have a message being sent to a global.html file that retrieves the settings and will send a message back to my injection script as soon as I figure out how to go about doing that.
Since I'm doing all of my work before the document loads, all of the methods I've found to send message back rely on a page object that I don't have.
Like everyone else at this point, I'm still climbing the learning curve, but here's how I've handled this problem:
I have a simple extension with no chrome and one injected end script (script.js). For the purpose of loading settings I've added a simple global page (proxy.html). When script.js is injected, it sends a getSettings message to proxy.html. proxy.html responds with a setSettings message, and script.js continues initialization.
The most helpful page I've found in the docs on this topic is Messages and Proxies.
proxy.html:
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript">
safari.application.addEventListener( "message", function( e ) {
if( e.name === "getSettings" ) {
e.target.page.dispatchMessage( "setSettings", {
sort_keys: safari.extension.settings.getItem( "sort_keys" )
} );
}
}, false );
</script>
</head>
<body></body>
</html>
script.js:
( function() {
var settings, init = function() {
// do extension stuff
};
// listen for an incoming setSettings message
safari.self.addEventListener( "message", function( e ) {
if( e.name === "setSettings" ) {
settings = e.message;
init();
}
}, false );
// ask proxy.html for settings
safari.self.tab.dispatchMessage( "getSettings" );
}() )
EDIT: like you said in your initial post update, the injected script doesn't have the same kind of access that a global HTML page would have. This is my working solution, imagine you want to know the value of setting "foo" in the injected script:
Injected script code:
function getMessage(msgEvent) {
if (msgEvent.name == "settingValueIs")
alert("Value for asked setting is: " + msgEvent.message);
}
safari.self.tab.dispatchMessage("getSettingValue", "foo"); // ask for value
safari.self.addEventListener("message", getMessage, false); // wait for reply
Global HTML code:
function respondToMessage(messageEvent) {
if (messageEvent.name == "getSettingValue") {
// getItem("foo");
var value = safari.extension.settings.getItem(messageEvent.message);
// return value of foo to injected script
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("settingValueIs", value);
}
}
safari.application.addEventListener("message",respondToMessage,false);
Hope this helps !
Initial post: I'm having the same 2nd problem as you, I can't access my settings (or secureSettings) from an injected script. In my case the script is loaded after page load, but even that way I can't use safari.extension.settings.
The only way it works is with a toolbar/button, the HTML behind that element can getItem and setItem as expected.
My conclusion is that, for some reason, injected scripts can't access settings (actually, they don't even seem to have access to the safari element). Bug or intended feature, that's left to figure out.
It took me several days, but I think I found a workable solution using the canLoad() messaging method. My injection script retrieves settings by calling the global HTML page like this:
settings = safari.self.tab.canLoad( event );
My global HTML file, in turn, returns those settings as:
settings = {
'setting1': safari.extension.settings.getItem( 'setting1' )
}
msgEvent.message = settings;
It's still a bit more "hacky" than I'd like. I can't seem to simply return the settings object itself, so I have to compile a new object by retrieving each setting manually. Not ideal, but it does seem to be effective.
run into the same problem, but the answer is easier than you can imagine: include the script in your global html.
<!DOCTYPE HTML>
<script type="text/javascript" src="cleanup.js"></script>
<script>
…
</script>
then you can access the settings as described in documentation safari.extension.settings.myKey
you can also upvote #Travis, because I got the idea from his post
//EDIT:
actually I don't really know whats wrong. Calling the settings as the first command works, but not at a later time. Additionally it seems to corrupting my complete script after the 2. injection. Need verification if it's only in my (difficult?) script.
//EDIT2:
now I got it to work to get back the settings object via dispatchMessage()
in your injected.js
function gotSettings(msgEvent) {
if (msgEvent.name === "SETTINGS") {
setts = msgEvent.message;
alert(setts.mySetting1);
// run the programm
}
}
safari.self.addEventListener("message", gotSettings, false);
safari.self.tab.dispatchMessage("getSettings");
and in global.html
switch (event.name) {
case "getSettings":
// send the settings data
event.target.page.dispatchMessage("SETTINGS", safari.extension.settings);
relying on this apple documentation